
    	e+                      d dl mZ d dlZd dlZd dlmZ d dlmZm	Z	 d dl
mZmZmZmZmZmZmZmZmZmZ d dlZd dlZd dlmZ d dlmZmZmZ d dlmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1 d d	l2m3Z3 d d
l4m5Z5 ddl6m7Z7 ddl8m9Z9m:Z: ddl;m<Z< ddl=m>Z>m?Z? ddl@mAZAmBZBmCZCmDZD ddlEmFZF ddlGmHZH ddlImJZJ erd dlKZLd dlMmNZN d dlOmPZP d dl4mQZQ ddlRmSZSmTZT d ZU G d de?eF          ZV G d deV          ZW G d deV          ZXdS )     )annotationsN)partial)FunctionType
MethodType)
TYPE_CHECKINGAnyCallableClassVarDictListMappingOptionalTupleType)Model)ColumnDataSourceImportedStyleSheet	Selection)AvgAggregator
CellEditorCellFormatterCheckboxEditorDataCube	DataTable
DateEditorDateFormatterGroupingInfo	IntEditorMaxAggregatorMinAggregatorNumberEditorNumberFormatterRowAggregatorStringEditorStringFormatterSumAggregatorTableColumn)convert_datetime_array)JupyterComm   )param_value_if_widget)CDN_DISTCSS_URLS)state)ReactiveReactiveData)clone_model
isdatetime	lazy_loadupdating   )Widget)Button)	TextInput)Document)DataDict)Comm)CellClickEventTableEditEventc                X    t          | t          j                  rt          |           S | S N)
isinstancenpndarrayr(   )vs    4lib/python3.11/site-packages/panel/widgets/tables.py#_convert_datetime_array_ignore_listrE   0   s)    !RZ   )%a(((H    c                      e Zd ZU  ej        i d          Z ej        i d          Z ej        i d          Z ej        ddd          Z	 ej
        d	d
          Z ej        g d          Z ej        dd          Z ej        g d          Z ej        i eefd          Z ej        i d          Z ej        i eefd          Z ej        d          ZdgZded<   g dZded<   ddddZded<   dZdX fd	Z ej        ddd          d             Z e!d             Z"dYd"Z#dZd%Z$d[d'Z%d\d+Z&dYd,Z'd]d.Z(d^d4Z)d^d5Z*d6 Z+e,dYd7            Z- fd8Z.d_ fd<Z/	 	 d`dadCZ0dbdEZ1dcdHZ2dddIZ3dddJZ4dK Z5dXdLZ6dM Z7dN Z8dedPZ9dfdQZ:dR Z;e!dS             Z<dgdTZ=dhdUZ>e!dV             Z?e!dW             Z@ xZAS )i	BaseTableaI  
        A dictionary mapping from index name to an aggregator to
        be used for hierarchical multi-indexes (valid aggregators
        include 'min', 'max', 'mean' and 'sum'). If separate
        aggregators for different columns are required the dictionary
        may be nested as `{index_name: {column_name: aggregator}}`defaultdoczr
        Bokeh CellEditor to use for a particular column
        (overrides the default chosen based on the type).zu
        Bokeh CellFormatter to use for a particular column
        (overrides the default chosen based on the type).FTz2
        Whether to generate a hierarchical index.)rJ   constantrK   (   &
        The height of each table row.z2
        The currently selected rows of the table.z*
        Whether to show the index column.z6
        A list of sorters to apply during pagination.
        A mapping from column name to alignment or a fixed column
        alignment, which should be one of 'left', 'center', 'right'.rJ   class_rK   zI
        A mapping from column name to a title to override the name with.zT
        A mapping from column name to column width or a fixed column
        width.N)rJ   valueClassVar[List[str]]_data_params)
formatterseditorswidthstitlesrR   
show_index_manual_params)hierarchicalname	selection"ClassVar[Mapping[str, str | None]]_renamec                "   i | _         g | _        i | _        g | _         t	                      j        dd|i| | j                            | j        ddg           | j        	                    d           | j        	                    d           d S )NrR   rV   rU    )
_renamed_cols_filters_index_mapping_edited_indexessuper__init__paramwatch_setup_on_changetrigger)selfrR   params	__class__s      rD   rg   zBaseTable.__init__n   s     !//u////
.L0IJJJ
9%%%
<(((((rF   ri   on_initc                    | j         | j                                         d S d |                                 D             | _        d S )Nc                X    i | ]'}t          |          |k    rt          |          n||(S ra   str).0cols     rD   
<dictcomp>z3BaseTable._compute_renamed_cols.<locals>.<dictcomp>}   s?     
 
 
:=CCCHHHS#
 
 
rF   )rR   rb   clear_get_fieldsrl   s    rD   _compute_renamed_colszBaseTable._compute_renamed_colsx   sW    :$$&&&F
 
AEAQAQASAS
 
 
rF   c                *    t          | j                  S r?   )len
_processedrz   s    rD   _lengthzBaseTable._length   s    4?###rF   eventsparam.parameterized.Eventc                    | j         d S | j         j        }t          |          t          |                                          k    rt	          d          d S )Nz>Cannot display a pandas.DataFrame with duplicate column names.)rR   columnsr}   drop_duplicates
ValueError)rl   r   colss      rD   	_validatezBaseTable._validate   s]    :Fz!t99D00223333 7 8 8 8 43rF   return	List[str]c                    | j         }t          | j        j                  }| j        rt          |          dk    r||z   }n|dd          |z   }|S Nr5   )indexeslistrR   r   r[   r}   )rl   r   	col_namess      rD   ry   zBaseTable._get_fields   sZ    ,+,,	  	1CLLA$5$5)+IIy0IrF   List[TableColumn]c                    | j         g S | j        }|                                 }t          |          dk    r| j                                         n| j         }|                     ||          S Nr5   )rR   r   ry   r}   reset_index_get_column_definitions)rl   r   fieldsdfs       rD   _get_columnszBaseTable._get_columns   sg    :I,!!##),W)9)9TZ##%%%tz++FB777rF   r   r   pd.DataFramec           	     `   dd l }| j        }g }|D ]}||j        v r	||         }n[|| j        v rRt          | j                  dk    r|j        }n2|j                            | j                            |                    }t          ||j                  rt          d          i }|j	        j
        }	|	dk    rt          d          }
t                      }n|	dk    rt          d          }
t                      }n|	d	k    r t          d
d          }
t                      }nt!          |          s|	dk    rYt          |          r(t          |j        d         t$          j                  rd}nd}t)          |d          }
t+                      }nt                      }
t-                      }t          | j        t0                    r| j        |
_        n,|| j        v r| j        |         |
_        n|| j        v rd|
_        || j        v rXt          | j        |         t4          t0          f          s1| j        |         }t          |t6                    rt9          |          }||v s|t7                      }|| j        v rXt          | j        |         t4          t0          f          s1| j        |         }
t          |
t<                    rt9          |
          }
t          | j        t@                    r| j        |d<   nt1          |          | j        v ret          | j        !                    t1          |                    t@                    r+| j        !                    t1          |                    |d<   nd|d<   | j"        !                    |t1          |                    }||v r3t          |          dk    r | j#        rdd$                    |          z  }n || j        v r|%                    d          rd}tM          dt1          |          |||
d|}|'                    |           |S )Nr   r5   z*DataFrame contains duplicate column names.iright)
text_alignbcenterfz0,0.0[00000])formatr   Mz%Y-%m-%dz%Y-%m-%d %H:%M:%Sleftwidthz	Index: %sz | level_ )fieldtitleeditor	formatterra   )(pandasr   r   r}   indexget_level_valuesr@   	DataFramer   dtypekindr"   r   r%   r   r!   r2   valuesdtdater   r   r$   r   rt   rV   dictr   r1   rU   r   rW   intgetrX   r[   join
startswithr'   append)rl   r   r   pdr   r   rv   data
col_kwargsr   r   r   date_formatr   columns                  rD   r   z!BaseTable._get_column_definitions   s   , G	# G	#Cbj  #w$$t|$$))8DD844T\5G5G5L5LMMD$-- O !MNNNJ:?D s{{+w???	"+x@@@	'))+>gVVV	%D!! 	(TS[[t99 6DKNBG!D!D 6",KK"5K)QQQ	#+--	%$/3// .'+	$$'''+s';	$$$$'-	$dl"":dl36G$PS+U+U"c*fj11 1(00Fg~~#do%%j9MPTVY{.[.[% OC0	i77 7 +I 6 6I$+s++ (&*k
7##ST[((ZC8Q8QSV-W-W(&*kooc#hh&?&?
7##&'
7#KOOCS22Eg~~#g,,"2"2t7H"2#ejj&9&99$$)A)A$  /s3xxu(.)/ /#-/ /F NN6""""rF   c                :    |D ]}|                      |           d S r?   )_process_on_change)rl   r   events      rD   rj   zBaseTable._setup_on_change   s2     	+ 	+E##E****	+ 	+rF   r   c                    |j         |j        }}t          |t                    r|ni                                 D ]}t          |t
          t          f          st          |t
                    r| j        n| j        }|	                                t          j	                    z
  D ])}	 |                    ||           # t          $ r Y &w xY wt          |t                    r|ni                                 D ]}t          |t
          t          f          st          |t
                    r| j        n| j        }|	                                t          j	                    z
  D ]}|                    ||           d S r?   )oldnewr@   r   r   r   r   _editor_change_formatter_change
propertiesr   remove_on_changer   	on_change)rl   r   r   r   model	change_fnprops          rD   r   zBaseTable._process_on_change   s   9eiS'T22:ccBBDD 	 	Eej-%@AA /9%/L/Lh++RVRhI))++e.>.@.@@  **4;;;;!   D
 (T22:ccBBDD 	1 	1Eej-%@AA /9%/L/Lh++RVRhI))++e.>.@.@@ 1 1i00001		1 	1s   'B>>
C
Cattrrt   r   r   r   c                :    | j                             d           d S )NrV   rh   rk   rl   r   r   r   s       rD   r   zBaseTable._editor_change  s    
9%%%%%rF   c                :    | j                             d           d S )NrU   r   r   s       rD   r   zBaseTable._formatter_change  s    
<(((((rF   c                    | j         !t          | j         t                    r| j         s	i | _        d S d t	          | j         j                  D             | _        d S )Nc                    i | ]\  }}||	S ra   ra   )ru   r   r   s      rD   rw   z3BaseTable._update_index_mapping.<locals>.<dictcomp>  s.     
 
 
5 u
 
 
rF   )r~   r@   r   rd   	enumerater   rz   s    rD   _update_index_mappingzBaseTable._update_index_mapping	  se    ?"j$&G&G"PTP_""$DF
 
%do&;<<
 
 
rF   c                D   | j         }|                                 \  | _         }|                                  | j        rv|tt	          | j         j                  }g }| j        D ]J}	 |j        |         }|                    |          }|                    |           ;# t          $ r Y Gw xY w|| _        d |                                D             | _	        d| j	        i}	| j
                                        D ]%\  }
\  }}|                     ||	|j        |
           &d S )Nc                4    i | ]\  }}|t          |          S ra   )rE   ru   krC   s      rD   rw   z)BaseTable._update_cds.<locals>.<dictcomp>#  s'    YYYDAqa<Q??YYYrF   r   )r~   	_get_datar   r]   r   r   r   	Exceptionitems_data_models_apply_updatesource)rl   r   old_processedr   r   r]   selividxmsgrefm_s                rD   _update_cdszBaseTable._update_cds  s@    $ 0 0""$$$> 
	'm74?011GI~  &,S1B!--++C$$S))))    H&DNYYDJJLLYYY
tz"<--// 	; 	;KC!QvsAHc::::	; 	;s   &7B
B+*B+c                    d|v r1|                     d           ot          | j                  dk    |d<   t                                          |          }|S )Ndisabledr5   editable)popr}   r   rf   _process_param_change)rl   rm   rn   s     rD   r   zBaseTable._process_param_change(  sX    %+ZZ
%;%;!;!VDL@Q@QUV@VF:..v66rF   rK   r9   Dict[str, Any]c                    t                                          |          }|                                 |d<   t          | j        t          | j                            |d<   |S )Nr   indices)r   selectedr   )rf   _get_propertiesr   r   r   r   r]   rl   rK   r   rn   s      rD   r   zBaseTable._get_properties.  se    WW,,S11
 $ 1 1 3 3
9 0i&G&G&G!
 !
 !

8 rF   rootOptional[Model]parentcommOptional[Comm]r   c                   |                      |          } | j        di |}|p|}|                     |j        dg|||           |                     |j        j        dg|||           ||f| j        |j        d         <   |S )Nr   r   idra   )r   _widget_type_link_propsr   r   r   r   )rl   rK   r   r   r   r   r   s          rD   
_get_modelzBaseTable._get_model6  s     ))#..
!!//J//}uxdDAAA.S$MMM(-vTXd^$rF   r   c                    |j         dk    r)d |j        D             |                                 k    rd S |                                 |_        d S )NrR   c                    g | ]	}|j         
S ra   r   )ru   cs     rD   
<listcomp>z-BaseTable._update_columns.<locals>.<listcomp>C  s    %E%E%E!ag%E%E%ErF   )r\   r   ry   r   )rl   r   r   s      rD   _update_columnszBaseTable._update_columnsB  sT    :  %E%Eu}%E%E%EIYIYI[I[%[%[ F))++rF   %Tuple[param.parameterized.Event, ...]Nonec                r   |D ]}|j         dk    r| j        r|j        dv rE|                     ||           t	          |t
                    r|                                 |_        ct          | d|j        z             r" t          | d|j        z             |           |                     ||           d S )N	triggered)rR   rY   _update_)
type	_updatingr\   r  r@   r   _get_groupings	groupingshasattrgetattr)rl   r   r   rK   r   r   r   r   s           rD   _manual_updatezBaseTable._manual_updateI  s      
	3 
	3Ez[((T^(666$$UE222eX.. <&*&9&9&;&;EOzEJ677 36j5:566u====$$UE2222
	3 
	3rF   c                N     j         s|S  fd j         D             }d  j         D             }t          j        t          |                                        t
                    |d<   |                    d           |                    d            j        r!d|v o|j        j	        d u }|rd|j        _	        nd}d }|
                    ||d|	          }|rd |j        _	        d |j        _	        |                    dgd
           |                    dgd
           |S )Nc                ^    g | ])}j                             |d          |d                    *S r  )rb   r   )ru   srl   s     rD   r  z&BaseTable._sort_df.<locals>.<listcomp>\  s4    WWWQ$$((7QwZ@@WWWrF   c                &    g | ]}|d          dk    S )dirascra   )ru   r  s     rD   r  z&BaseTable._sort_df.<locals>.<listcomp>]  s!    ===1QuX&===rF   _index_Tr   Fc                    | j         j        dvr| S 	 |                     d          j                                        S # t
          $ r | cY S w xY w)NSUOr   )r   r   fillnart   lowerr   )rv   s    rD   tabulator_sorterz,BaseTable._sort_df.<locals>.tabulator_sorterm  s`     y~U**
zz"~~)//111   


s   +> AA	mergesort)	ascendingr   key)r   inplace)sortersrA   aranger}   astypert   r   rY   r   r\   sort_valuesdrop)rl   r   r   r  renamer  	df_sorteds   `      rD   _sort_dfzBaseTable._sort_dfY  sQ   | 	IWWWW$,WWW=====	 	#b''**11#669i    ? 	&@28=D+@F ( 'F	 	 	 NN6Y[&6 # 8 8	  	( BHM#'IO 
T222	{D999rF   c                `   g }| j         D ]3\  }}|
||j        vrt          |t          t          f          r ||          }:t          |t
          j                  rt          |j        |j	                  }n|}||         }||t          j        |          r||k    }nt          |t          t          f          r|s|                    |          }nRt          |t                    r*|\  }}	||	|||	k    }n*|	||k    }n!||k    ||	k    z  }nt!          d| d          |                    |           5|                    |                     |                     |rE|d         }|D ]}
||
z  }| j        r$|j                            | j                  }||z  }||         }|S )z
        Filter the DataFrame.

        Parameters
        ----------
        df : DataFrame
           The DataFrame to filter

        Returns
        -------
        DataFrame
            The filtered DataFrame
        N'zE filter value not understood. Must be either a scalar, tuple or list.r   )rc   r   r@   r   r   rh   	Parameterr  ownerr\   rA   isscalarr   setisintupler   r   extend_get_header_filtersre   r   )rl   r   filterscol_namefiltvalr   maskstartendr   edited_masks               rD   _filter_dataframezBaseTable._filter_dataframe  s    "m !	! !	!NHd#
(B(B$z :;; T"XX$00 dj$)44\F{S!! 3}C$-- 3 {{3''C'' 3 
s=S[]!3;DD[!5=DD"EMfck:DD  "2X "2 "2 "2 3 3 3 NN4    t//33444 	1:D  	# *!x}}T-ABBk)DB	rF   c           	        g }t          | dg           D ]}|d         }|d         }|d         }t          | di           pi }||j        v r	||         }n]|| j        v rSt          | j                  dk    r|j        }n4|j                            | j                            |                    }nt          |t                    rt          |          dk    r	|d         }n|s|j        	                    |          }|dk    r|
                    ||k               |d	k    r|
                    ||k               -|d
k    r|
                    ||k                N|dk    r|
                    ||k               o|dk    r|
                    ||k               |dk    r|
                    ||k               |dk    rNt          |t          t          j        f          s|g}|
                    |                    |                     |dk    r2|
                    |j                            |dd                     =|dk    r/|
                    |j                            |                     r|dk    r/|
                    |j                            |                     |dk    r	|                    |i                               dd          }	|                    |i                               dd          }
|                    |
          }|	r7|D ]2}|
                    |j                            |dd                     3P|j                            |d         dd          }|dd          D ]"}||j                            |dd          z  }#|
                    |           |dk    rt)          d          t)          d|d          |S )Nr3  r   r
  rR   header_filtersr5   r   =z!=<>z>=z<=inlikeF)caseregexstartsendskeywordsmatchAll	separator rD  zRegex filtering not supported.zFilter type z not recognized.)r  r   r   r}   r   r   r@   r   r   r
  r   rA   rB   r/  rt   contains
startsWithendsWithr   splitr   )rl   r   r3  r5  r4  opr6  filt_defrv   	match_allsepmatchesmatchs                rD   r2  zBaseTable._get_header_filters  s   D)R00 ;	H ;	HDG}HfBw-Ct%5r::@bH2:%%lT\))t|$$))(CC(33DL4F4Fx4P4PQQCC #t$$ s88q==a&CC )..%%CSyyscz****tscz****ssSy))))ssSy))))tscz****tscz****t!#bj'9::G3%Csxx}}----vsw//%u/MMNNNNxsw11#667777vsw//445555z!!$LL266:::uMM	ll8R0044[#FF))C.. )!( Y Ysw'7'7EQV'7'W'WXXXXY 7++GAJU%+PPD!( Q Q 0 0U% 0 P PPNN4((((w !ABBB !F!F!F!FGGGrF   c                   t          |t          t          t          f          st	          j        |          rg }nt          |t          t          f          r?t          |d          r,t          |j	        d         
                                          ng }nat          |          }t          |t          j                  s$t          t          |           j         d          |t          d          |g}|D ],}|j        j                            | j        |j                   -| j                            ||f           |                                  dS )a  
        Adds a filter to the table which can be a static value or
        dynamic parameter based object which will automatically
        update the table when changed..

        When a static value, widget or parameter is supplied the
        filtering will follow a few well defined behaviors:

          * scalar: Filters by checking for equality
          * tuple: A tuple will be interpreted as range.
          * list: A list will be interpreted as a set of discrete
                  scalars and the filter will check if the values
                  in the column match any of the items in the list.

        Arguments
        ---------
        filter: Widget, param.Parameter or FunctionType
            The value by which to filter the DataFrame along the
            declared column, or a function accepting the DataFrame to
            be filtered and returning a filtered copy of the DataFrame.
        column: str or None
            Column to which the filter will be applied, if the filter
            is a constant value, widget or parameter.

        Raises
        ------
        ValueError: If the filter type is not supported or no column
                    was declared.
        _dinfokwz@ filter must be a constant value, parameter, widget or function.NzRWhen filtering with a parameter or widget, a column to filter on must be declared.)r@   r0  r   r.  rA   r-  r   r   r  rV  r   r+   rh   r+  r   r
  __name__r,  ri   r   r\   rc   r   )rl   filterr   depsdeps        rD   
add_filterzBaseTable.add_filter   s[   < fudC011 	R[5H5H 	DDz :;; 	9@9R9RZ4d+2244555XZDD*622Ffeo66 . DJJ$7 "0 "0 "0 1 1 1   "- . . . 8D 	> 	>CIO!!$"2CH====ff-...rF   c                `    fd| j         D             | _         |                                  dS )z>
        Removes a filter which was previously added.
        c                &    g | ]\  }}|u	||fS ra   ra   )ru   r   r5  rY  s      rD   r  z+BaseTable.remove_filter.<locals>.<listcomp>6  s5     0 0 0NVT .. !$...rF   N)rc   r   )rl   rY  s    `rD   remove_filterzBaseTable.remove_filter2  sF    0 0 0 0dm 0 0 0rF   c                    t          |t          t          j        f          sd |D             S t          |t          j                  r$|j        j        dk    r|                                S |S )Nc                ,    g | ]}t          |          S ra   rs   ru   rC   s     rD   r  z-BaseTable._process_column.<locals>.<listcomp><  s    +++qCFF+++rF   r   )r@   r   rA   rB   r   r   tolist)rl   r   s     rD   _process_columnzBaseTable._process_column:  se    &4"455 	,++F++++fbj)) 	#fl.?3.F.F==??"rF   Tuple[pd.DataFrame, DataDict]c                6    |                      | j                  S r?   )_process_df_and_convert_to_cdsrR   rz   s    rD   r   zBaseTable._get_dataB  s    224:>>>rF   c                0    dd l }                     |          }|g i fS t           j        j        |j                  r$d t          |j        j                  D             nd|j        v rdnd}|j        j	        p|gt                    dk    r|                                }t          j        |          } j        s3t                    dk    r fd|                                D             }| fd|                                D             fS )Nr   c                &    g | ]\  }}|d| n|S Nr   ra   ru   r   ns      rD   r  z<BaseTable._process_df_and_convert_to_cds.<locals>.<listcomp>K  :       Aq !"	q  rF   r   level_0r5   c                $    i | ]\  }}|v	||S ra   ra   )ru   r   rC   r   s      rD   rw   z<BaseTable._process_df_and_convert_to_cds.<locals>.<dictcomp>V  s)    FFFTQQg5E5EAq5E5E5ErF   c                    i | ]?\  }}t          |t                    r|nt          |                              |          @S ra   )r@   rt   rd  )ru   r   rC   rl   s      rD   rw   z<BaseTable._process_df_and_convert_to_cds.<locals>.<dictcomp>W  sI    jjjUYUVXYAs++7AAQ9M9Ma9P9PjjjrF   )r   r;  r@   rR   r   
MultiIndexr   namesr   r\   r}   r   r   from_dfrY   r   )rl   r   r   default_indexr   r   s   `    @rD   rg  z(BaseTable._process_df_and_convert_to_cdsE  s7   ##B'':r6Mdj&66 	7 %bhn55  GG
 +2RZ*?*?YYWMx}56Gw<<!!!B'++ 	G3w<<!#3#3FFFFTZZ\\FFFDjjjj]a]g]g]i]ijjjjjrF   c                    dd l }|| j        |<   | j        D| j        | j        ur8 |j        dd           5  || j        |<   d d d            d S # 1 swxY w Y   d S d S d S )Nr   mode.chained_assignment)r   rR   r~   option_context)rl   r   arrayr   s       rD   _update_columnzBaseTable._update_columnY  s    "
6?&4:T_+L+L""#<dCC 0 0*/'0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '&+L+Ls   AAAc                   dd l }| j        | j        sg S t          | j        j        |j                  r(d t          | j        j        j                  D             S d| j        j        v rdnd}| j        j        j	        p|gS )Nr   c                &    g | ]\  }}|d| n|S rj  ra   rk  s      rD   r  z%BaseTable.indexes.<locals>.<listcomp>k  s:       Aq !"	q  rF   r   rn  )
r   rR   rY   r@   r   rq  r   rr  r   r\   )rl   r   rt  s      rD   r   zBaseTable.indexese  s    :T_I
("-88 	 %dj&6&<==    '.1C&C&C
 %677rF   c                   ddl }t          j        | j        j                                                  sd}n!| j        j                                        dz   }t          ||j                  r|r&|                    d          }|xj        |z  c_         |j	        | j        |g          }||j
        | d         }t          j        |           5  || _        ddd           n# 1 swxY w Y   	 d| _        | j                            d           d| _        n# d| _        w xY w|                     |          \  }}	 d| _        |                     ||           d| _        dS # d| _        w xY wt          ||j                  r|| j        j        |<   |^t'          | j                  |k    rFt          j        |           5  | j        j
        | d         | _        ddd           n# 1 swxY w Y   |                     | j        j
        dd                   \  }}	 d| _        |                     ||           d| _        dS # d| _        w xY wt          |t(                    rN|rJ	  |j        |          }n # t*          $ r  |j        |          }Y nw xY w|                     ||           dS dS t+          d	          )
a  
        Streams (appends) the `stream_value` provided to the existing
        value in an efficient manner.

        Arguments
        ---------
        stream_value: (pd.DataFrame | pd.Series | Dict)
          The new value(s) to append to the existing value.
        rollover: int
           A maximum column size, above which data from the start of
           the column begins to be discarded. If None, then columns
           will continue to grow unbounded.
        reset_index: (bool, default=True)
          If True and the stream_value is a DataFrame,
          then its index is reset. Helps to keep the
          index unique and named `index`

        Raises
        ------
        ValueError: Raised if the stream_value is not a supported type.

        Examples
        --------

        Stream a Series to a DataFrame
        >>> value = pd.DataFrame({"x": [1, 2], "y": ["a", "b"]})
        >>> tabulator = Tabulator(value=value)
        >>> stream_value = pd.Series({"x": 4, "y": "d"})
        >>> tabulator.stream(stream_value)
        >>> tabulator.value.to_dict("list")
        {'x': [1, 2, 4], 'y': ['a', 'b', 'd']}

        Stream a Dataframe to a Dataframe
        >>> value = pd.DataFrame({"x": [1, 2], "y": ["a", "b"]})
        >>> tabulator = Tabulator(value=value)
        >>> stream_value = pd.DataFrame({"x": [3, 4], "y": ["c", "d"]})
        >>> tabulator.stream(stream_value)
        >>> tabulator.value.to_dict("list")
        {'x': [1, 2, 3, 4], 'y': ['a', 'b', 'c', 'd']}

        Stream a Dictionary row to a DataFrame
        >>> value = pd.DataFrame({"x": [1, 2], "y": ["a", "b"]})
        >>> tabulator = Tabulator(value=value)
        >>> stream_value = {"x": 4, "y": "d"}
        >>> tabulator.stream(stream_value)
        >>> tabulator.value.to_dict("list")
        {'x': [1, 2, 4], 'y': ['a', 'b', 'd']}

        Stream a Dictionary of Columns to a Dataframe
        >>> value = pd.DataFrame({"x": [1, 2], "y": ["a", "b"]})
        >>> tabulator = Tabulator(value=value)
        >>> stream_value = {"x": [3, 4], "y": ["c", "d"]}
        >>> tabulator.stream(stream_value)
        >>> tabulator.value.to_dict("list")
        {'x': [1, 2, 3, 4], 'y': ['a', 'b', 'c', 'd']}
        r   Nr5   T)r%  rR   Fr   z=The stream value provided is not a DataFrame, Series or Dict!)r   rA   isfiniterR   r   maxr@   r   r   concatilocrh   discard_eventsr  rk   rg  _streamSerieslocr}   r   r   stream)rl   stream_valuerolloverr   r   value_index_startcombinedstream_datas           rD   r  zBaseTable.streamr  s   r 	{4:+//1122 	; ! $
 0 4 4 6 6 :lBL11 '	^ 8+77T7BB""&77"" ry$*l!;<<H##=(4%d++ & &%
& & & & & & & & & & & & & & &'!%
""7+++!&&&&&(,(K(KL(Y(Y%L+'!%[(333!&&&&&bi00 	^0<DJN,-#DJ((B(B)$// = =!%(!<DJ= = = = = = = = = = = = = = =(,(K(KDJO\^\_\_L`(a(a%L+'!%[(333!&&&&&d++ 	^ 4;#/2<#=#=LL! ; ; ;#,29\#:#:LLL;L(333334 4 \]]]sZ   C((C,/C,4!D 	D&E( (	E1G--G14G1#I	 		I-I> >JJc                   | j         %t          dt          |           j         d          ddl}t          | j         |j                  s*t          dt          | j                   j         d          t          |j                  r,fdj        D             }|                     ||           dS t          |j	                  r{d	v r6fd

                                D             }|                    d	           n(j        t          
                                          i}|                     ||           dS t          t                    rt          | j         j                  }
                                D ]|\  }}|D ]t\  }}	t          |t                    r"t!          |j        |j        |j        pd          }|r|	| j         j        ||f<   P|	| j         j        ||                    |          f<   u}|                                dS t          dt                    j         d          )a  
        Efficiently patches (updates) the existing value with the `patch_value`.

        Arguments
        ---------
        patch_value: (pd.DataFrame | pd.Series | Dict)
          The value(s) to patch the existing value with.
        as_index: boolean
          Whether to treat the patch index as DataFrame indexes (True)
          or as simple integer index.

        Raises
        ------
        ValueError: Raised if the patch_value is not a supported type.

        Examples
        --------

        Patch a DataFrame with a Dictionary row.
        >>> value = pd.DataFrame({"x": [1, 2], "y": ["a", "b"]})
        >>> tabulator = Tabulator(value=value)
        >>> patch_value = {"x": [(0, 3)]}
        >>> tabulator.patch(patch_value)
        >>> tabulator.value.to_dict("list")
        {'x': [3, 2], 'y': ['a', 'b']}

        Patch a Dataframe with a Dictionary of Columns.
        >>> value = pd.DataFrame({"x": [1, 2], "y": ["a", "b"]})
        >>> tabulator = Tabulator(value=value)
        >>> patch_value = {"x": [(slice(2), (3,4))], "y": [(1,'d')]}
        >>> tabulator.patch(patch_value)
        >>> tabulator.value.to_dict("list")
        {'x': [3, 4], 'y': ['a', 'd']}

        Patch a DataFrame with a Series. Please note the index is used in the update.
        >>> value = pd.DataFrame({"x": [1, 2], "y": ["a", "b"]})
        >>> tabulator = Tabulator(value=value)
        >>> patch_value = pd.Series({"index": 1, "x": 4, "y": "d"})
        >>> tabulator.patch(patch_value)
        >>> tabulator.value.to_dict("list")
        {'x': [1, 4], 'y': ['a', 'd']}

        Patch a Dataframe with a Dataframe. Please note the index is used in the update.
        >>> value = pd.DataFrame({"x": [1, 2], "y": ["a", "b"]})
        >>> tabulator = Tabulator(value=value)
        >>> patch_value = pd.DataFrame({"x": [3, 4], "y": ["c", "d"]})
        >>> tabulator.patch(patch_value)
        >>> tabulator.value.to_dict("list")
        {'x': [3, 4], 'y': ['c', 'd']}
        NzCannot patch empty .r   zPatching an object of type z) is not supported. Please provide a dict.c                `    i | ]*}|t          |                                                   +S ra   )r   r   )ru   r   patch_values     rD   rw   z#BaseTable.patch.<locals>.<dictcomp>  sA          >D[0668899     rF   )as_indexr   c                .    i | ]\  }}|d          |fgS )r   ra   )ru   r   rC   r  s      rD   rw   z#BaseTable.patch.<locals>.<dictcomp>  s9     $ $ $7;q!AW-q12$ $ $rF   r5   z$Patching with a patch_value of type z> is not supported. Please provide a DataFrame, Series or Dict.)rR   r   r
  rX  r   r@   r   r   patchr  r   r   r\   r   r   sliceranger8  stopstepr  r  r   _patch)
rl   r  r  r   patch_value_dictr   r   rC   indrR   s
    `        rD   r  zBaseTable.patch  s   f :I4::3FIIIJJJ$*bl33 	;d4:.>.>.G ; ; ;  
 k2<00 	       HSH[      JJ'(J;;;;;RY// 	+%%$ $ $ $?J?P?P?R?R$ $ $  !$$W----$/$4d;;L;L;N;N6O6O#P JJ'(J;;;;;T** 	4:-..G#))++ G G1$% G GLS%!#u-- H#CIsxQGG G16
sAv..AF
W]]1-=-=(=>>G KK$$$$$PtK7H7H7Q P P P  rF   c                :    | j         }|                     |          S )h
        Returns the current view of the table after filtering and
        sorting are applied.
        )r~   r(  rl   r   s     rD   current_viewzBaseTable.current_view7  s     _}}R   rF   c                f    | j         s| j        j        dd         S | j        j        | j                  S )zE
        Returns a DataFrame of the currently selected rows.
        Nr   )r]   r  r  rz   s    rD   selected_dataframezBaseTable.selected_dataframe@  s6    
 ~ 	.$)"1"-- %dn55rF   r?   r   r   )r   r   )r   r   )r   r   r   r   r   r   )r   r   )r   rt   r   r   r   r   rK   r9   r   r   NNN
rK   r9   r   r   r   r   r   r   r   r   )r   r   r   r   )r   r  r   r   rK   r9   r   r   r   r   r   r   r   r  )r   r   r   r   )r   re  )r   r   r   re  NTT)BrX  
__module____qualname__rh   r   aggregatorsrV   rU   Booleanr[   Integer
row_heightr   r]   rY   r!  ClassSelectorr   rt   r   rX   r   rW   r+  rR   rT   __annotations__rZ   r_   _BaseTable__abstractrg   dependsr{   propertyr   r   ry   r   r   rj   r   r   r   r   r4   r   r   r   r   r  r  r(  r;  r2  r\  r_  rd  r   rg  ry  r   r  r  r  r  __classcell__rn   s   @rD   rH   rH   5   s        %*R .F G G GK ej *= > > >G B -= > > >J !5= D5 6 6 6L r 0) * * *J 
2 ,5 6 6 6I t 2- . . .J ej *9 : : :G %$Rs JH I I IJ UZ )L M M MF !U T3K F   F EOD)))E)0	L1111+ + +N    
 d3 3G     J) ) ) ) ) ) U]7$555
 
 65
 $ $ X$8 8 8 8   8 8 8 8L L L L\+ + + +1 1 1 1$& & & &) ) ) )
 
 
 ; ; ; X;*          6:?C
 
 
 
 
, , , ,3 3 3 3 ' ' ' 'R< < < <|> > >@0 0 0 0d    ? ? ? ?k k k k(0 0 0 
8 
8 X
8g^ g^ g^ g^RZ Z Z Zx ! ! X! 6 6 X6 6 6 6 6rF   rH   c                      e Zd ZU dZ ej        dd          Z ej        dg dd          Z ej        d	d
          Z	 ej
        d	d          Z ej
        d	d          Z ej        dd          Z ej        dd          Zej        dgz   Zded<   eeeedZdd	iZded<   d	d	d	dZded<   ed$d            Zd Zd Zd Zd% fd"Zd# Z xZ S )&r   a  
    The `DataFrame` widget allows displaying and editing a pandas DataFrame.

    Note that editing is not possible for multi-indexed DataFrames, in which
    case you will need to reduce the DataFrame to a single index.

    Also note that the `DataFrame` widget will eventually be replaced with the
    `Tabulator` widget, and so new code should be written to use `Tabulator`
    instead.

    Reference: https://panel.holoviz.org/reference/widgets/DataFrame.html

    :Example:

    >>> DataFrame(df, name='DataFrame')
    FzI
        Whether clicking on a table cell automatically starts edit mode.rI   	force_fit)nonefit_columnsfit_viewportr  ao  

        Determines the column autosizing mode, as one of the following options:

        ``"fit_columns"``
          Compute column widths based on cell contents while ensuring the
          table fits into the available viewport. This results in no
          horizontal scrollbar showing up, but data can get unreadable
          if there is not enough space available.

        ``"fit_viewport"``
          Adjust the viewport size after computing column widths based
          on cell contents.

        ``"force_fit"``
          Fit columns into available space dividing the table width across
          the columns equally (equivalent to `fit_columns=True`).
          This results in no horizontal scrollbar showing up, but data
          can get unreadable if there is not enough space available.

        ``"none"``
          Do not automatically compute column widths.rJ   objectsrK   Nz
        Whether columns should expand to the available width. This
        results in no horizontal scrollbar showing up, but data can
        get unreadable if there is no enough space available.z
        Integer indicating the number of columns to freeze. If set, the
        first N columns will be frozen, which prevents them from
        scrolling out of frame.z
       Integer indicating the number of rows to freeze. If set, the
       first N rows will be frozen, which prevents them from scrolling
       out of frame; if set to a negative value the last N rows will be
       frozen.Tz
        Allows the reordering of a table's columns. To reorder a
        column, click and drag a table's header to the desired
        location in the table.  The columns on either side will remain
        in their previous order.a/  
        Allows to sort table's contents. By default natural order is
        preserved.  To sort a column, click on its header. Clicking
        one more time changes sort direction. Use Ctrl + click to
        return to natural order. Use Shift + click to sort multiple
        columns simultaneously.r  rS   rZ   )sumr~  minmeanr[   r^   _source_transforms)r]   r!  r   r_   r   Type[Model]c                ,    | j         rt          nt          S r?   )r[   r   r   rz   s    rD   r   zDataFrame._widget_type  s    ,;xx);rF   c                @   | j         g S | j        }t          | j         j                  }| j        rt          |          dk    r||z   }n|dd          |z   }t          |          dk    r| j                                         n| j         }|                     ||          S r   )rR   r   r   r   r[   r}   r   r   )rl   r   r   r   s       rD   r   zDataFrame._get_columns  s    :I,+,,	  	1CLLA$5$5)+IIy0I),W)9)9TZ##%%%tz++Ir:::rF   c                \   | j         g S g }t          | j        d d         | j        dd                    D ]u\  }}t          |          |k    r|| j        t          |          <   |                     |          }|                    t          t          |          |                     v|S )Nr   r5   )getterr  )rR   zipr   rt   rb   _get_aggregatorsr   r   )rl   groupsgroup	agg_groupaggss        rD   r  zDataFrame._get_groupings  s    :I #DL"$5t|ABB7G H H 	M 	ME95zzU""16"3u::.((33DMM,c%jjdKKKLLLLrF   c           	     0   t          | j                            d          j                  }| j                            |g           }t          |t                     s|g}g }|D ]t          t                    sfd|D                                             D ]u\  }}t          |t                    r| j
                            |          }t          |t                    r,|                     |t          |                               v|S )Nnumber)includec                    i | ]}|S ra   ra   )ru   rv   col_aggss     rD   rw   z.DataFrame._get_aggregators.<locals>.<dictcomp>  s    BBBcCBBBrF   )field_)r   rR   select_dtypesr   r  r   r@   r   r   rt   _aggregators
issubclassr#   r   )rl   r  numeric_colsr  expanded_aggsrv   aggr  s          @rD   r  zDataFrame._get_aggregators  s#   DJ44X4FFNOO##E2..$%% 	6D 	? 	?Hh-- CBBBB\BBB$NN,, ? ?Sc3'' 5+//44Cc=11 ?!((CHH)=)=)=>>>	?
 rF   rK   r9   r   c                    t                                          |          }| j        r9t          t	          g g                     |d<   |                                 |d<   |S )N)row_indiceslabels)r   targetgrouping)rf   r   r[   r   r   r  r   s      rD   r   zDataFrame._get_properties  sd    WW,,S11
 	;#3"UW9X9X9X#Y#Y#YJx %)%8%8%:%:Jz"rF   c                    |j         D ]i}| j                            |j        |j                  }| j        | j                            |          dz            }|                     |          |_        jd S r   )r  rb   r   r  r   r   r  r  )rl   r   gr  r   s        rD   _update_aggregatorszDataFrame._update_aggregators  sq     	9 	9A&**18QX>>EL!3!3E!:!:1!<=E 11%88AMM	9 	9rF   )r   r  r  )!rX  r  r  __doc__rh   r  	auto_editObjectSelectorautosize_moder  r  frozen_columnsfrozen_rowsreorderablesortablerH   rZ   r  r&   r   r    r   r  r  r_   r  r   r   r  r  r   r  r  r  s   @rD   r   r   J  s          " e 2L M M MI )E( G< G< G<B9: : :M0  %- 3A B B BK
 #U]4 6# $ $ $N
  %- 3   K  %- 3$ % % %K u}T 0# $ $ $H +4*Bm_*TNTTTT ]m L
 ?Md=SSSSS d$3 3G     < < < X<; ; ;
 
 
        9 9 9 9 9 9 9rF   r   c            
           e Zd ZU dZ ej        i d          Z ej        g d          Z ej	        dd          Z
 ej        g d          Z ej        g d          Z ej        g d	          Z ej        i d
          Z ej        g d          Z ej        i eefd          Z ej        eefd          Z ej        g d          Z ej        dg d          Z ej        ddddg          Z ej        dd          Z ej        ddd          Z ej        d           Z ej        d!d"          Z ej        deee fd#          Z! ej        dd$          Z" ej        d%g d&d'(          Z# ej        g ed)*          Z$ ej        i d+          Z%g d,Z&d-e'd.<   g d/Z(d-e'd0<   e&g d1z   Z)d-e'd2<   e*j+        e(z   Z+d-e'd3<   d4gZ,d-e'd5<   dddddddd6dd7	Z-d8e'd9<   d:Z.d;e'd<<   e/d=         gZ0d fd>	Z1 ej2        d?dd@          dA             Z3 ej2        dBdC          dD             Z4e5dE             Z6 fdFZ7dd fdKZ8dL Z9ddMZ: fdNZ; fdOZ< fdPZ=ddQZ>dR Z?ddSZ@i fdTZAddUZBdV ZCdW ZDeEd fdX	            ZFd fdY	ZGeE fdZ            ZH fd[ZId\ ZJd] ZKdd^d fdaZLddfZMddiZNd fdmZOdn ZP	 	 dd fdtZQddvZRddzZSdd|ZTdddZUi i fdZVddZWdddZXeYdd            ZZ xZ[S )	Tabulatora:  
    The `Tabulator` widget wraps the [Tabulator js](http://tabulator.info/)
    table to provide a full-featured, very powerful interactive table.

    Reference: https://panel.holoviz.org/reference/widgets/Tabulator.html

    :Example:

    >>> Tabulator(df, theme='site', pagination='remote', page_size=25)
    za
        Dictionary mapping from column name to a HTML element
        to use as the button icon.rI   zc
        List of expanded rows, only applicable if a row_content function
        has been defined.Fzb
        Whether to embed the row_content or render it dynamically
        when a row is expanded.zr
        List of client-side filters declared as dictionaries containing
        'field', 'type' and 'value' keys.zg
        List indicating the columns to freeze. The column(s) may be
        selected by name or index.z
        List indicating the rows to freeze. If set, the
        first N rows will be frozen, which prevents them from scrolling
        out of frame; if set to a negative value the last N rows will be
        frozen.z0
        Dictionary mapping defining the groups.z9
        Groups rows in the table by one or more columns.rO   rP   zk
        Whether to enable filters in the header or dictionary
        configuring filters for each column.)rQ   rK   z!
        List of columns to hide.fit_data_table)fit_datafit_data_fillfit_data_stretchr  r  )rJ   r  NTlocalremote)rJ   
allow_Noner  r5   zS
        Currently selected page (indexed starting at 1), if pagination is enabled.   )r5   NzE
        Number of rows to render per page, if pagination is enabled.)rJ   boundsrK   z
        A function which is given the DataFrame row and should return
        a Panel object to render as additional detail below the row.)rK      rN   aG  
        Defines the selection mode of the Tabulator.

          - True
              Selects rows on click. To select multiple use Ctrl-select,
              to select a range use Shift-select
          - False
              Disables selection
          - 'checkbox'
              Adds a column of checkboxes to toggle selections
          - 'checkbox-single'
              Same as 'checkbox' but header does not allow select/deselect all
          - 'toggle'
              Selection toggles when clicked
          - int
              The maximum number of selectable rows.
        zx
        A function which given a DataFrame should return a list of
        rows by integer index, which are selectable.simple)rJ   siter  midnightmodern	bootstrap
bootstrap4materializebulmazsemantic-uifast
bootstrap5z/
        Tabulator CSS theme to apply to table.r  zb
       List of extra CSS classes to apply to the Tabulator element
       to customize the theme.)rJ   	item_typerK   z]
       Tabulator formatter specification to use for a particular column
       header title.)rR   page	page_size
paginationr!  r3  rS   rT   )r  r  
selectabler[   _config_params)expandedrow_contentembed_content_content_paramsrZ   r   _priority_changescell_styles)	r]   r  r  r   r  header_alignr=  stylestitle_formattersr^   r_   )   i'  zClassVar[Tuple[int, int]]_MAX_ROW_LIMITSzfont-awesomec                n   dd l }|                    dd           }|                    dd           }t          ||j        j        j        j                  r
|}|j        }nd }|                    di           }d | _        d | _        i | _	        d|v | _
        g | _        i | _        d | _         t                      j        dd|i| || _        | j                            | j        | j                   |r|                     |           |r|                     |           ||j        | j        _        d S d S )Nr   on_clickon_editconfigurationr  rR   ra   )pandas.io.formats.styler   r@   ioformatsstyleStylerr   _computed_styler_child_panels_explicit_pagination_on_edit_callbacks_on_click_callbacks
_old_valuerf   rg   _configurationrh   ri   _update_childrenr  r  r  _todo)	rl   rR   rm   r   click_handleredit_handlerr  r  rn   s	           rD   rg   zTabulator.__init__h  sO   &&&&

:t44zz)T22eVY.4;<< 	EJEEE

?B77
 $$0F$:!"$#% //u////+
.0DEEE 	)MM-((( 	'LL&&&${DJ rF   rR   ro   c                   | j         | j        rdS t          j                            |           5  | j        rnj| j        d         t          | j                   cxk     r| j        d         k    rn nd| _        n*t          | j                   | j        d         k    rd| _        ddd           n# 1 swxY w Y   d| _        dS )zM
        Ensure large tables automatically enable remote pagination.
        Nr   r5   r  r  F)	rR   r  rh   parameterizedr  r[   r
  r}   r  rz   s    rD   _apply_max_sizezTabulator._apply_max_size  s	   
 :!:F //55 	+ 	+  +%a(3tz??UUUUd>RST>UUUUUU")TZ4#7#:::"*	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ %*!!!s   A3B//B36B3r  )ri   c                    d| _         d S r  )r  rz   s    rD   _set_explicict_paginationz#Tabulator._set_explicict_pagination  s    $(!!!rF   c                T    t          |t                    st          d|           d S )NzThe Tabulator widget expects the provided `value` Pandas DataFrame to have unique indexes, in particular when it has to deal with click or edit events. Found this duplicate index: )r@   r   r   )r   r  s     rD   _validate_iloczTabulator._validate_iloc  sG    
 $$$ 	MEHM M  	 	rF   c                     t                      j        |  | j        Fg }| j        | j        j        }	 | j        j        | _        || j        _        d S # t
          $ r Y d S w xY wd S r?   )rf   r   rR   r  r  r   )rl   r   todorn   s      rD   r   zTabulator._validate  s    6"":!Dz%z'!Z-
#'
       "!s   A 
A"!A"r   Model | Noner   r  c                    | j                                         D ]}|                    |           t                                          |           d S r?   )r  r   _cleanuprf   )rl   r   prn   s      rD   r*  zTabulator._cleanup  sT    #**,, 	 	AJJtrF   c                   | j                             |j        |j                  }| j        dk    r!| j        }|j        | j        dz
  |z  z   |_        | j                            |j        |j                  }| j        j	        
                    |          }|                     ||           ||_        || j        vrM|| j        j        vr| j        j	        |j                 |_        n"| j        |         j        |j                 |_        |j        dk    r|j        rsdd l} |j        |j        g|j        g          }|                     |          }|r6|d                                         r| j                            |           d S d S d S | j        "| j        |         j        |j                 |_        | j        D ]&}	t5          j        t9          |	|          d           '|                                  d S | j                            d g           D ]&}	t5          j        t9          |	|          d           '| j                            |g           D ]&}	t5          j        t9          |	|          d           'd S )Nr  r5   
table-editr   )r   F)schedule)rb   r   r   r  r  rowr  rd   rR   r   get_locr%  buttonsr   r  
event_nameprer   r   r2  anyre   r   r  r   r  r.   executer   _update_styler  )
rl   r   	event_colnrowsr   r  r   	filter_dfr3  cbs
             rD   _process_eventzTabulator._process_event  s   &**5<FF	?h&&NE	49Q;"55EI!%%ei;;z'',,C&&&	DL((
 222"j.uy9"j38C |++y %####(BL%+OOO	229== 5wqz~~// 5(//444445 5 5 5 ?. $	 : ?	 JEI1 F FBM'"e"4"4uEEEEE""$$$$$.224<< B Bgb%005AAAAA.229bAA B Bgb%005AAAAAB BrF   c                    ddl m}m} |                    ||          }|dk    rdnd| }t           d| | d}| j        |g| j        _        |S )Nr*   )_TABULATOR_THEMES_MAPPING
THEME_PATHrJ   	tabulator
tabulator_zbundled/datatabulator/z.min.css)models.tabulatorr=  r>  r   r,   r   __css_raw__)rl   theme	resourcesr=  r>  theme_fname	theme_urls           rD   
_get_themezTabulator._get_theme  s    LLLLLLLL*..ue<<%228MV8M8MRRzR5RRR	(-6KD)rF   c                   |j         | j        vr]t                                          ||           |j         dv r2t	          d |j                                        D                       sd S |                     |j                  |_	        d S )N)rV   rU   c              3  N   K   | ] }t          |t          t          f          V  !d S r?   )r@   rt   r   rb  s     rD   	<genexpr>z,Tabulator._update_columns.<locals>.<genexpr>  s0      OOq
1sDk22OOOOOOrF   )
r\   r  rf   r  r4  r   r   _get_configurationr   r  )rl   r   r   rn   s      rD   r  zTabulator._update_columns  s    :T000GG##E5111
777OOEI<L<L<N<NOOOOO 8 "55emDDrF   c                   | j                                         | _        dd l} |j        |          |                               }|rW|d         }|D ]}||z  }| j        r6| j         j        j        pd         	                    | j                  }||z  }|         fdj
        D             }t                                          |          S )Nr   r   c                ,    i | ]}||         j         S ra   )r   )ru   rv   r   s     rD   rw   z+Tabulator._process_data.<locals>.<dictcomp>  s.     
 
 
$'CC
 
 
rF   )rR   copyr  r   r   r2  re   r   r\   r/  r   rf   _process_data)	rl   r   r   r3  r7  r   r:  r   rn   s	          @rD   rP  zTabulator._process_data  s     *//++R\$**2.. 	1:D  	# *!$*"2"7"B7CHHI]^^k)DB
 
 
 
+-:
 
 
 ww$$T***rF   c                   | j         dk    s| j         t                                                      S dd l}|                     | j                  }|                     |          }| j        }| j        dz
  |z  }|j	        |||z            }t          | j        j        |j                  r$d t          |j        j                  D             }nd|j        v rdnd}|j        j        p|g}t#          |          dk    r|                                }t'          j        |                                          }|d |D             fS )Nr  r   r5   c                &    g | ]\  }}|d| n|S rj  ra   rk  s      rD   r  z'Tabulator._get_data.<locals>.<listcomp>  rm  rF   r   rn  c                b    i | ],\  }}t          |t                    r|nt          |          |-S ra   )r@   rt   r   s      rD   rw   z'Tabulator._get_data.<locals>.<dictcomp>  s7    LLLtq!As++7AAQLLLrF   )r  rR   rf   r   r   r;  r(  r  r  r  r@   r   rq  r   rr  r   r\   r}   r   r   rs  r   )
rl   r   r   r8  r8  page_dfr   rt  r   rn   s
            rD   r   zTabulator._get_data	  sP   ?h&&$**<77$$&&&##DJ//]]21e#'%u,-dj&66 	7 %bhn55  GG
 +2RZ*?*?YYWMx}56Gw<<!))++G'006688LLtLLLLLrF   c                *   | j         | j        | j         j        ri S | j        }|rS	 |j        x| _        }n# t
          $ r d | _        i cY S w xY w|i S | j        j        |_        |                                 n| j        }|i S dt          | j	                  z   t          | j        dv           z   t          t          | j                            z   }| j        dk    r| j        dz
  | j        z  }|| j        z   }i }|j                                        D ]c\  \  }}	}
| j        dk    r||k     s||k    r ||z  }||vri |t          |          <   |
|t          |                   |t          |	          z   <   dt'          j                    j        |dS )Nr5   )checkboxzcheckbox-singler  )r   r   )rR   r  emptyr~   r  r   r  _computer}   r   r   r  boolr  r  r  r  ctxr   uuiduuid4hex)rl   	recomputer   styleroffsetr8  r9  r  rr  r  s              rD   _get_style_datazTabulator._get_style_data   s   :!3tz7G!3I_ 	+139%   (,%			 ~	:+FLOO*F>IS&&&T_@_-_)`)``cfgklpl|g}g}c~c~~?h&&Yq[$.0E$.(C))++ 	. 	.IFQA(**IIcJA!#s1vv,-F3q66N6#a&&=))jll&777s   6 AAc                    | j         | j        d S | j        }| j        dk    r&| j        }| j        dz
  |z  }|j        |||z            }|                     |          S Nr  r5   )rR   selectable_rowsr~   r  r  r  r  )rl   r   r8  r8  s       rD   _get_selectablezTabulator._get_selectableB  sk    :!5!=4_?h&&NEYq[%'Ee,-B##B'''rF   c                    |                      |          }d|i}| j                                        D ] \  }\  }}|                     g |||           !d S )Nr  )rb  r   r   r   )rl   r^  r  r   r   r   r   s          rD   r6  zTabulator._update_styleL  sk    %%i00f%<--// 	0 	0KC!Qr33////	0 	0rF   c                x   | j         | j        i S ddlm} | j        }| j        dk    r&| j        }| j        dz
  |z  }|j        |||z            }i }| j	        rt          t          |                    n| j        D ]>}||v r||         ||<    ||                      |j        |                             ||<   ?|S )Nr*   )panelr  r5   )r  rR   paneri  r~   r  r  r  r  r  r  r}   r   )rl   r   ri  r   r8  r8  childrenr   s           rD   _get_childrenzTabulator._get_childrenR  s    #tz'9I      _?h&&NEYq[%'Ee,-B$($6I%B...DM 	B 	BACxx!!f#eD$4$4RWQZ$@$@AArF   c                    |j         d         }i }|                                D ]F\  }}	||	j        v r|	j        |         d         }
n|	                    ||||          }
d|
_        |
||<   G|S )Nr   r   )r   r   r   r   )r   r   r   r   margin)rl   panelsrK   r   r   r   r   modelsr   r+  r   s              rD   _get_model_childrenzTabulator._get_model_childrenc  sz    htnLLNN 	 	DAqai	#q)S$=='ELF1IIrF   c                    t          |          t          |          k    st          |t                    rdS t          |          t          |          k    rdS |j        |j        k                                    S )z
        Comparator that checks whether DataFrame indexes have changed.

        If indexes and length are unchanged we assume we do not
        have to reset various settings including expanded rows,
        scroll position, pagination etc.
        TF)r
  r@   r   r}   r   r4  )rl   r   r   s      rD   _indexes_changedzTabulator._indexes_changedo  sf     99S		!!ZT%:%:!4XXS!!5	SY&++---rF   c                n   t                      t                      }}d}|D ]}|j        dk    rft          |          dk    rSt          |j                  t          |j                  z
  }t          |j                  t          |j                  z  }s|j        dk    r |                     |j        |j                  s&|j        |v r| j        r| j        dk    r|j        dk    r
g | _         d S | j	        | 
                    fd|D                       x| _	        }| j                                        D ]{\  }\  }}	t          j        |         dd          \  }
}}|D ]}|                             |
           |                     |||
||          }d|i}|                     g |||           |d S )	Nr  r  r  r   r5   rR   r  r!  c                "    i | ]}||         S ra   ra   )ru   r   
old_panelss     rD   rw   z.Tabulator._update_children.<locals>.<dictcomp>  s    ---!Q
1---rF   rk  )r.  r\   r}   r   r   rs  r  r  r   r  rl  r   r   r.   _viewsr*  rq  r   )rl   r   cleanupreusepage_eventsr   child_panelsr   r   r   r   rK   r   r   rk  r   rw  s                   @rD   r  zTabulator._update_children}  s   9 
	 
	EzZ''CKK1,<,<ei..3uy>>9EIUY7zW$$)>)>uy%))T)T$z[((((**uzY/F/F "'
,0,>,>----u----
 -
 	
\  <--// 	0 	0KC!Q#l3/3OD#t / /3((....//c4D H x(Cr33////	0 	0rF   c                \   | j         dk    rA| j        }| j        }t          ||z  t	          ||z            z   d          }| j        |k    rd S t                                          ||           |                                  | 	                                 | 
                                 d S rd  )r  r   r  r~  rY  r  rf   r  r6  _update_selectabler   )rl   r  r  followlengthr8  max_pagern   s          rD   r  zTabulator._stream  s    ?h&&\FNE65=4u+=+==qAAHyH$$)))!!!""$$$$$rF   c                   | j                                         D ]"\  }\  }}|                     g d|i||           #|r@| j        r9| j        }| j        }	t          ||	z  t          ||	z            z   d          | _        t                      
                    |||           |r| j        r|                                  d S d S d S )Nr  r5   )r   r   r   r  r   r  r~  rY  r  rf   r  _update_max_page)rl   r  r  r   r  r   r   r   r  r8  rn   s             rD   r  zTabulator.stream  s    #|1133 	C 	COC%rHf#5ucBBBB 	Cdo 	C\FNEFEMD,>,>>BBDI|X{;;; 	$do 	$!!#####	$ 	$ 	$ 	$rF   c                   | j         s| j        rd| _        |                                  d S | j        dk    rM| j        }| j        dz
  |z  |z   i }|                                D ]\  }}fd|D             }|r|||<   |}|sd S t                      	                    |           | 
                                 |                                  d S )NFr  r5   c                6    g | ]\  }}|k    |k     ||fS ra   ra   )ru   r  r6  r9  r8  s      rD   r  z$Tabulator._patch.<locals>.<listcomp>  s9     9 9 9#s E\\cCii *.7iirF   )r3  r!  r  r   r  r  r  r   rf   r  r6  r~  )	rl   r  r8  filteredr  r   r9  r8  rn   s	         @@rD   r  zTabulator._patch  s   < 	4< 	"DNF?h&&NEYq[%'E+CH"[[]] ) )	69 9 9 9 9v 9 9 9 )"(HQKE 	Fu!!!!!rF   c                H   t          d |D                       rg | _        d| j        rd S |r(t          fd|D                       r| j        dk    rd S |r@t          fd|D                       r%| j        s|                                 \  | _        }d S t          d |D                        } t                      j        |  | j        r(| 	                                 | 
                                 |                     |           |                                  d S )Nc              3  ,   K   | ]}|j         d k    V  dS )r3  Nr\   )ru   r   s     rD   rK  z(Tabulator._update_cds.<locals>.<genexpr>  s)      ;;5uzY&;;;;;;rF   )r  r  r!  r3  c              3  :   K   | ]}|j         d d         v V  d S )Nr   r  ru   er{  s     rD   rK  z(Tabulator._update_cds.<locals>.<genexpr>  s3      GG1AFk#2#&66GGGGGGrF   r  c              3  *   K   | ]}|j         v V  d S r?   r  r  s     rD   rK  z(Tabulator._update_cds.<locals>.<genexpr>  s*      BBaAFk1BBBBBBrF   c              3  (   K   | ]}|j         d v V  dS )ru  Nr  )ru   r  s     rD   rK  z(Tabulator._update_cds.<locals>.<genexpr>  s;       
 
>?AF99
 
 
 
 
 
rF   )r4  re   r  allr  r   r~   rf   r   r  _update_selectedr6  r~  )rl   r   r   r^  r{  rn   s       @rD   r   zTabulator._update_cds  sm   ;;F;;;;; 	&#%D A> 	F 	GGGGGGGGG 	DO_fLfLfF 	BBBB6BBBBB 	4? 	!%!1!1DOQF 
 
CI
 
 
 
 
 
	 	V$$? 	$!!###!!###9%%%!!!!!rF   c                    |                                  }| j                                        D ]"\  }\  }}|                     g d|i||           #d S )Nre  )rf  r   r   r   )rl   r  r   r   r   s        rD   r~  zTabulator._update_selectable  si    ))++
#|1133 	P 	POC%r$5z#BE3OOOO	P 	PrF   c                   | j         }| j        }t          ||z  t          ||z            z   d          }d|f| j        j        _        | j                                        D ]"\  }\  }}| 	                    g d|i||           #d S )Nr5   r  )
r   r  r~  rY  rh   r  r  r   r   r   )rl   r  r8  r  r   r   r   s          rD   r  zTabulator._update_max_page  s    vu}tF5L'9'991=="#X
#|1133 	G 	GOC%rJ#95#FFFF	G 	GrF   r   r   r   c                 	 i }| j         dk    r| j        | j        j        | j                 j        }g }|j        D ]]}	 | j        j                            |          }|                     ||           |	                    |           N# t          $ r Y Zw xY w| j        }| j        dz
  |z  		|z   	fd|D             |d<    t                      j        |i | d S )Nr  r5   c                2    g | ]}|k    |k     |z
  S ra   ra   )ru   r  r9  r8  s     rD   r  z.Tabulator._update_selected.<locals>.<listcomp>  s5     !< !< !<s$'JJ3s77 "%U3:77rF   r   )r  rR   r  r]   r   r   r~   r0  r%  r   KeyErrorr  r  rf   r  )rl   r   r   kwargsr   rC   r  r8  r9  r8  rn   s           @@rD   r  zTabulator._update_selected  s"   ?h&&4:+AJODN39EG\  ?088;;D''4000NN4((((   HNEYq[%'E+C!< !< !< !< !<g !< !< !<F9  &3F33333s    A
B
BBr   rt   rx  
np.ndarrayc                   dd l }| j        dk    rW| j        j        j        }|| j        j        ||f<    |j        dd           5  || j        |<   d d d            n# 1 swxY w Y   d S | j        }| j	        dz
  |z  }||z   }| j        j
        ||         j        j        }|| j        j        ||f<    |j        dd           5  || j        j        ||f<   d d d            d S # 1 swxY w Y   d S )Nr   r  rv  r5   )r   r  r~   r   r   rR   r  rw  r  r  r  )rl   r   rx  r   r   r8  r8  r9  s           rD   ry  zTabulator._update_column  s   ?h&&O)0E,1DJN5&=)""#<dCC 0 0*/'0 0 0 0 0 0 0 0 0 0 0 0 0 0 0F1e#Ek$U3Y/5<(-
uf}%R8$?? 	7 	716DOv.	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7s$   AA!A CC#&C#r   	List[int]c                z   | j         dk    r	|| _        d S | j        }| j        dz
  |z  | j        j        fd|D                      j        }g }|j        D ]]}	 | j        j        	                    |          }| 
                    ||           |                    |           N# t          $ r Y Zw xY w|| _        d S )Nr  r5   c                    g | ]}|z   S ra   ra   )ru   r  r8  s     rD   r  z/Tabulator._update_selection.<locals>.<listcomp>  s    %C%C%CCeCi%C%C%CrF   )r  r]   r  r  r~   r  r   r   rR   r0  r%  r   r  )rl   r   r8  r   rC   r  r8  s         @rD   _update_selectionzTabulator._update_selection  s    ?h&&$DNF1e#$%C%C%C%C7%C%C%CDJ 	 	Az'//22##At,,,t$$$$    s   A
B$$
B10B1rK   r9   r   c                   t                                          |          }|                     |d                   |d<   |                                 |d<   | j        |d<   | j        r:| j        }t          || j        z  t          || j        z            z   d          |d<   t          | j        t                    r | j                            d          rd|d<   n
| j        |d<   |S )	Nr   r  r  r   r5   r  rV  select_mode)rf   r   rL  rb  r   r  r   r~  r  rY  r@   r  rt   r   )rl   rK   r   r  rn   s       rD   r   zTabulator._get_properties   s    WW,,S11
&*&=&=j>S&T&T
?#$($8$8$:$:
=! $
9? 	b\F%()?$vdnG\B]B])]_`%a%aJz"dos++ 	80J0J:0V0V 	8(2J}%%(,J}%rF   c                   d|v sd|v r^|                      |                    d| j                            }|                    d| j                  t          |          gz   |d<   t          j        | |          }d|v r1|                    d           ot          | j	                  dk    |d<   d|v r| j
        fd|d         D             |d<   d	|v rQd
d l}| j        sF| j        ?t          | j        j        |j                  s |d	         | j        j        j        pdgz   |d	<   d|v r|                                 |d<   |S )NrC  stylesheets)urlr   r5   r   r  c                *    g | ]}|d k     r|z   n|S )r   ra   )ru   ra  r  s     rD   r  z3Tabulator._process_param_change.<locals>.<listcomp>9  s6     % % %-.AEEqq% % %rF   hidden_columnsr   r   re  )rH  r   rC  r   r  r   r/   r   r}   r   r   r   rY   rR   r@   r   rq  r\   rf  )rl   rm   rG  r   r  s       @rD   r   zTabulator._process_param_change.  s   f 7 7

7DJ(G(GHHI$*JJ}d>N$O$O"y111S %F=! /f==%+ZZ
%;%;!;!VDL@Q@QUV@VF:F""\F% % % %282G% % %F=! v%%? itz'=jQUQ[QacecpFqFq'=+12B+CtzGWG\Gg`gFh+h'(&&(,(<(<(>(>F$%rF   r   r   r   r   r   c                   t          ddt          |t                    |          t          _        t                                          ||||          }|p|}|                                 x| _        }| 	                    |||||          |_
        |                     |g d|||           |                     dd|||           |S )Nzpanel.models.tabulatorDataTabulator)r  r!  r   r3  z
cell-clickr-  )r   rK   r   )r3   r@   r)   r  r   rf   r   rl  r  rq  rk  r   _register_events)rl   rK   r   r   r   r   r|  rn   s          rD   r   zTabulator._get_modelD  s     "+$oz$7T7TVZ"
 "
	 ""3fd;;}u,0,>,>,@,@@\11#tVT
 
 	 J J JCQUW[\\\lL3UYZZZrF   r'   c                   i }| j         r(t          | j         t                    r|j        | j         vr|S | j         dk    r|j        | j        v rt          | j                  dk    r| j        j        }n<| j        j                            | j                            |j                            }|j	        j
        dv rd|d<   nn|j	        j
        dk    rd|d<   dd d|d	<   nPt          |          s|j	        j
        d
k    rd|d<   n+d|d<   n%t          |j        t                    rd|d<   nd|d<   |S | j         |j                 }t          |t                    rRt          |          }|                    dd          }|                    dd           }|                    dd           }ni }d }d }|dv ri| j                            d|d|j                   d}|                    dd          du r*| j                            d|j                   |d= d|d<   |dk    r|sddi}||d<   |r||d	<   |r||d<   |r||d<   |S )NTr5   uifr  headerFilterr   	tickCross)tristateindeterminateValueheaderFilterParamsr   Fr
  funcplaceholderselectautocompleteThe zT filter has been deprecated, use instead the "list" filter type to configure column r   r   zeSetting "values" to True has been deprecated, instead set "valuesLookup" to True to configure column valuesLookupheaderFilterFuncheaderFilterPlaceholder)r=  r@   r   r   r   r}   rR   r   r   r   r   r2   r   r   r   rh   warningr   )rl   r   fspecrv   filter_typefilter_paramsfilter_funcfilter_placeholders           rD   _get_filter_speczTabulator._get_filter_specU  s   " 	z$2Et'L'L 	'-|4;N'N'NL D((|t|++t|$$))**CC**;;DL<N<Nv|<\<\]]C9>U**,4E.))Y^s**,7E.)?C[_2`2`E.//__ 1	#(=(=,1E.)),0E.))FM:66 - ).n%%(,n%L)&,7k4(( 	& --M'++FD99K'++FD99K!.!2!2=$!G!GMK!% 444JW{ W WFLlW W   !K  511T99
""WFLlW W   "(+04n-&   +T2M +n 	8*7E&' 	4(3E$% 	B/AE+,rF   column_objsr   List[Dict[str, Any]]c           	        t          |          }i }g }| j        }| j        r|                    ddi           t	          |t
                    rJ|                    d          r5|                    d          rdnd}|                    d|ddd	d
d           g }| j        D ]t	          t                    r)|                    |
                                         @fd|D             }|r6|                    |d                    |                    |d                    ||z  }d | j                                        D             }t          |          D ]\  }	fd|                                D             }
dj        i}t	          | j        t
                    r| j        |d<   n#j        | j        v r| j        j                 |d<   t	          | j        t
                    r| j        |d<   n#j        | j        v r| j        j                 |d<   | j                            j                  }t	          |t
                    r||d<   nAt	          |t(                    r,t)          |          }|
                    d          |d<   ||d<   | j                            j                  }|r||d<   nAt	          |t(                    r,t)          |          }|
                    d          |d<   ||d<   | j        j                 }j        | j        v rlt1          | j                  dk    r| j        j        j        }nT| j        j                            | j                            j                            j        }n| j        j        |         }|j        dk    rd|d<   n|j        dv rd|d<   n|j        dk    rd|d<   | j                            j                  }j        | j        v r|d|d<   t	          |t
                    r||d <   nAt	          |t(                    r,t)          |          }|
                    d          |d <   ||d!<   |                    d           d"v rs| j         !                    d#|d          d$j                   d%|d <   |                    d!i                               d&d          d	u r|d!         d&= |d!         d'          j        | j        v s	|	| j        v rd	|d(<   t	          | j"        t(                    rGt	          | j"                            j                  t
                    r| j"        j                 |d)<   |#                    | $                                         |
rQ|
d         }||v r#||         d*                             |           `||gd+}|||<   |                    |           |                    |           |S ),Nr   expandrV  z-singler   rowSelectionr   FTrM   )r   titleFormatterhozAlign
headerSortfrozenr   c                *    g | ]}|j         k    |S ra   r  )ru   r  rv   s     rD   r  z-Tabulator._config_columns.<locals>.<listcomp>  s     AAAa!'S.....rF   r   c                .    i | ]\  }}|d  |D             S )c                ,    g | ]}t          |          S ra   rs   )ru   gcs     rD   r  z8Tabulator._config_columns.<locals>.<dictcomp>.<listcomp>  s    111CGG111rF   ra   )ru   r  
group_colss      rD   rw   z-Tabulator._config_columns.<locals>.<dictcomp>  s=     
 
 
!z 11j111
 
 
rF   c                ,    g | ]\  }}j         |v |S ra   r  )ru   r  r  r   s      rD   r  z-Tabulator._config_columns.<locals>.<listcomp>  s4       +%<:-- ---rF   r   r  headerHozAlignr
  formatterParamsr  titleFormatterParamsr5   r   	timestampsorteriufr  r   booleanr   r   editorParamsr  r  zT editor has been deprecated, use instead the "list" editor type to configure column r   r   r  r  r   r   )r   r   )%r   r  r  r   r@   rt   r   endswithr  r   r   remover  r   r   r   r   r  rU   r   r   r  rb   r   r}   rR   r   r   r   dtypesr   rV   rh   r  rW   updater  )rl   r  r  r   r  r   orderedr   r  r   matching_groupscol_dictr   title_formatterr4  r   r   r  
group_dictrv   r   s                      @@rD   _config_columnszTabulator._config_columns  s   ;''_
 	NNX    j#&& 		:+@+@+L+L 		$--i88LBBnENN+"'$#     & 	0 	0C#s## 0{s334444AAAA;AAA 0NN47+++&&tAw///;
 
%)[%6%6%8%8
 
 
 #7++ M	) M	)IAv   /7~~/?/?  O  .H$/3// E'+$$00'+v|'D$$+S11 M-1->)**!222-1->v|-L)*++FL99I)S)) 8(1%%It,, 8 OO	(1f(=(=%.7*+"377EEO C-<)**OT22 C 11	-<-@-@-H-H)*3B/0)&,7H|t|++t|$$)) J,2EE J,==dl>P>PQWQ]>^>^__eEE
)(3zS  %0""u$$%-""s""%."\%%fl33F|t|++',$&#&& 2%+""FD)) 2f%+ZZ%7%7"+1(||H%%)CCC
""[8H- [ [JP,[ [   &,"<<3377%HHDPP 0:^,^<<|t222a4;N6N6N%)"$+t,, >DKOOFL<Y<Y[^1_1_ >$(K$=!OOD11&99::: )'*F??5M),33H===" (z 
 !+uz****x((((rF   r   c                   t          | j                  }d|vr
| j        |d<   | j        rd|v rt	          d          |                     |          |d<   | j        |d<   | j        dv rd|d<   n| j        r
| j        |d<   |S )	z6
        Returns the Tabulator configuration.
        r  r   zLGroups must be defined either explicitly or via the configuration, not both.dataTree)stretch_heightstretch_bothz100%	maxHeightheight)	r   r  r  r  r   r  r[   sizing_moder  )rl   r   r  s      rD   rL  zTabulator._get_configuration	  s     T011},,*./M,'; 	D955 C D D D#'#7#7#@#@i $($5j!AAA)/M+&&[ 	2&*kM(#rF   	table.csvfilenamec                    | j                                         D ]B\  }\  }}|                     i d|i||           |                     i d|j         i||           CdS )z
        Triggers downloading of the table as a CSV or JSON.

        Arguments
        ---------
        filename: str
            The filename to save the table as.
        r  downloadN)r   r   r   r  )rl   r  r   r   r   s        rD   r  zTabulator.download  s}      $|1133 	Q 	QOC%rJ#95#FFFrJEN0B#CUCPPPP	Q 	QrF   c                    t          |          }d|vrd|d<   d|vrd|d<   t          d	i |}t          |          }d|vrd|d<   t          d	i |}|                    | |dd           ||fS )
a+  
        Returns a menu containing a TextInput and Button widget to set
        the filename and trigger a client-side download of the data.

        Arguments
        ---------
        text_kwargs: dict
            Keyword arguments passed to the TextInput constructor
        button_kwargs: dict
            Keyword arguments passed to the Button constructor

        Returns
        -------
        filename: TextInput
            The TextInput widget setting a filename.
        button: Button
            The Button that triggers a download.
        r\   FilenamerR   r  Download)tabler  zZ
        table.filename = filename.value
        table.download = !table.download
        )codera   )r   r8   r7   js_on_click)rl   text_kwargsbutton_kwargsr  buttons        rD   download_menuzTabulator.download_menu(  s    & ;''$$",K+%%#.K ++{++]++&&$.M&!((-((Tx@@ H 	 	 	 rF   callback Callable[[TableEditEvent], None]c                :    | j                             |           dS )aq  
        Register a callback to be executed when a cell is edited.
        Whenever a cell is edited on_edit callbacks are called with
        a TableEditEvent as the first argument containing the column,
        row and value of the edited cell.

        Arguments
        ---------
        callback: (callable)
            The callback to run on edit events.
        N)r  r   )rl   r  s     rD   r  zTabulator.on_editL  s!     	&&x00000rF    Callable[[CellClickEvent], None]Optional[str]c                l    || j         vr
g | j         |<   | j         |                             |           dS )a  
        Register a callback to be executed when any cell is clicked.
        The callback is given a CellClickEvent declaring the column
        and row of the cell that was clicked.

        Arguments
        ---------
        callback: (callable)
            The callback to run on edit events.
        column: (str)
            Optional argument restricting the callback to a specific
            column.
        N)r  r   )rl   r  r   s      rD   r  zTabulator.on_clickZ  sA     111/1D$V, (//99999rF   r   c                T    | j         }| j        dk    r|S |                     |          S )r  r  )r~   r  r(  r  s     rD   r  zTabulator.current_viewl  s/     _?h&&I}}R   rF   r?   )r   r(  r   r  r  r  )NTTr  )r   rt   rx  r  )r   r  r  r  r  )r   r'   r   r   )r  r   r   r  )r   r  r   r   )r  )r  rt   )r  r  )r  r  r   r  )r   r   )\rX  r  r  r  rh   r   r1  r   r   r  r  r3  r  r  r  groupbyr  r   rt   r  rY  r=  r  r  layoutr  r  r  r  r	   r  r  r   r  re  rC  theme_classesr  rT   r  r  r  rH   rZ   r  r_   r
  r-   _stylesheetsrg   r  r!  r#  staticmethodr%  r   r*  r;  rH  r  rP  r   rb  rf  r6  rl  rq  rs  r  r4   r  r  r  r   r~  r  r  ry  r  r   r   r   r  r  rL  r  r  r  r  r  r  r  r  s   @rD   r  r    s6        	 	 ej *& ' ' 'G uz" +   H "EM% 6# $ $ $M ej *- . . .G  UZ 1& ' ' 'N %*R .   K UZ )3 4 4 4F ej *< = = =G '5&r4+ LH I I IL )U(t C0 1 1 1N  UZ 1$ % % %N "U!*: E E E   F &%dt/6.AC C CJ 5= )V W W WD b AH I I II !%. &H I I IK r 0) * * *J %$dC- 4  J& %enT 88 9 9 9O !E  #
 #
 #
23 3 3E EJrS ?" # # #M "uz" 3   ) ) )L    + + +N     ,8:f:f:f+fOffff*3*B^*SNSSSS.4X5555 $dT4-T3 3G     2>O====^,-L+ + + + + +6 U]7$555* * 65* U]<t,,,) ) -,) 	 	 \	
 
 
 
 
      
#B #B #BJ   E E E E E+ + + + +:M M M M M. 8  8  8  8D( ( (0 0 0 0 !#    "
 
 
 
. . .0 0 08 
% 
% 
% 
% 
% X
%	$ 	$ 	$ 	$ 	$ 	$ " " " " X"," " " " "*P P P
G G G LP 4 4 4 4 4 4 4 4&7 7 7 7$! ! ! !"       . 6:?C      "? ? ? ?Bq q q qf   $Q Q Q Q Q )+" "  "  "  " H1 1 1 1: : : : :$ ! ! ! X! ! ! ! !rF   r  )Y
__future__r   datetimer   r[  	functoolsr   typesr   r   typingr   r   r	   r
   r   r   r   r   r   r   numpyrA   rh   bokeh.modelr   bokeh.modelsr   r   r   bokeh.models.widgets.tablesr   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   bokeh.util.serializationr(   pyviz_commsr)   r  r+   io.resourcesr,   r-   io.stater.   reactiver/   r0   utilr1   r2   r3   r4   baser6   r  r7   inputr8   r   r   bokeh.documentr9   bokeh.models.sourcesr:   r;   rA  r<   r=   rE   rH   r   r  ra   rF   rD   <module>r     s   " " " " " "            * * * * * * * *                       
            H H H H H H H H H H                                          < ; ; ; ; ; # # # # # # + + + + + + - - - - - - - -       - - - - - - - -                              B''''''------      AAAAAAAA  
R6 R6 R6 R6 R6f R6 R6 R6jO9 O9 O9 O9 O9	 O9 O9 O9dY! Y! Y! Y! Y!	 Y! Y! Y! Y! Y!rF   