11/*jshint esversion: 6 */ 
2- function  filterPills ( ) { Alpine . data ( "filterPillsHandler" , l => ( { localData :l , localFilterKey :"" , localFilterTitle :"" , isExternalFilter :! 1 , shouldRenderAsHTML :! 1 , shouldWatchPillValues :! 1 , pillsSeparator :"," , pillValues :null , pillHasValues :! 1 , displayString :"" , generateLocalFilterPillImplodedValues ( l ) { if ( void  0 !== l ) { var  t , i = "---tablepillsseparator---" , e = RegExp ( i , "g" ) ; if ( t = Array . isArray ( l ) ?l . join ( i ) :l , this . shouldRenderAsHTML || ( t = this . removeHTMLTags ( t ) ) , null !== t ) return  t . replace ( e , this . pillsSeparator ) } return "" } , clearExternalFilterPill ( ) { this . isExternalFilter && ( this . externalFilterPillsVals [ this . localFilterKey ] = [ ] , this . displayString = this . generateLocalFilterPillImplodedValues ( this . externalFilterPillsVals [ this . localFilterKey ] ) , this . updatePillHasValues ( ) , this . resetSpecificFilter ( this . localFilterKey ) ) } , trigger :{ "@filterpillupdate.window" ( l ) { this . watchForUpdateEvent ( l ) } } , checkEventIsValid ( l , t ) { return  this . tableName === l && this . localFilterKey === t } , watchForUpdateEvent ( l ) { if ( this . checkEventIsValid ( l . detail . tableName ?? "" , l . detail . filterKey ?? "" ) ) { let  t = l . detail . pillItem ?? "" ; if ( this . shouldRenderAsHTML || ( t = this . removeHTMLTags ( t ) ) , "" != t ) { if ( this . isExternalFilter ) { let  i = this . externalFilterPillsVals [ this . localFilterKey ] ; i . push ( t ) , this . updatePillValues ( i ) } else  this . updatePillValues ( t ) } } } , updatePillValues ( l ) { return  this . pillValues = l , this . displayString = this . generateLocalFilterPillImplodedValues ( l ) , this . updatePillHasValues ( ) , this . displayString } , updatePillHasValues ( ) { this . pillHasValues = this . displayString . length > 0 } , init ( ) { this . localFilterKey = this . localData . filterKey ?? "unknown" , this . localFilterTitle = this . localData . filterPillTitle ?? "Unknown" , this . pillsSeparator = this . localData . separator ?? "," , this . shouldWatchPillValues = Boolean ( this . localData . watchForEvents ?? 0 ) , this . isExternalFilter = Boolean ( this . localData . isAnExternalLivewireFilter ?? 0 ) , this . shouldRenderAsHTML = Boolean ( this . localData . renderPillsAsHtml ?? 0 ) , this . pillValues = this . localData . pillValues ?? null , this . $nextTick ( ( ) => { this . isExternalFilter ?this . updatePillValues ( this . externalFilterPillsVals [ this . localFilterKey ] ) :this . updatePillValues ( this . pillValues ) } ) , this . isExternalFilter && this . shouldWatchPillValues && this . $watch ( "externalFilterPillsVals." + this . localFilterKey , l => { this . updatePillValues ( l ) } ) } } ) ) } export  default  filterPills ; 
2+ 
3+ function  filterPills ( )  { 
4+     Alpine . data ( 'filterPillsHandler' ,  ( data )  =>  ( { 
5+         localData : data , 
6+         localFilterKey : '' , 
7+         localFilterTitle : '' , 
8+         isExternalFilter : false , 
9+         shouldRenderAsHTML : false , 
10+         shouldWatchPillValues : false , 
11+         pillsSeparator : ',' , 
12+         pillValues : null , 
13+         pillHasValues : false , 
14+         displayString : '' , 
15+         generateLocalFilterPillImplodedValues ( filterPillValues ) 
16+         { 
17+             if ( typeof ( filterPillValues )  !==  'undefined' ) 
18+             { 
19+                 var  temporarySeparatorString  =  '---tablepillsseparator---' ; 
20+                 var  regex  =  new  RegExp ( temporarySeparatorString ,  'g' ) ; 
21+                 var  joinedValues ; 
22+ 
23+                 if ( Array . isArray ( filterPillValues ) ) 
24+                 { 
25+                     joinedValues  =  filterPillValues . join ( temporarySeparatorString ) ; 
26+                 } 
27+                 else 
28+                 { 
29+                     joinedValues  =  filterPillValues ;     
30+                 } 
31+ 
32+                 if ( ! this . shouldRenderAsHTML ) 
33+                 { 
34+                     joinedValues  =  this . removeHTMLTags ( joinedValues ) ; 
35+                 } 
36+ 
37+                 if  ( joinedValues  !==  null ) 
38+                 { 
39+                     let  replacedJoinedValues  =  joinedValues . replace ( regex ,  this . pillsSeparator ) ; 
40+                     return  replacedJoinedValues ; 
41+     
42+                 } 
43+                 return  "" ; 
44+             } 
45+             return  "" ; 
46+         } , 
47+         clearExternalFilterPill ( ) 
48+         { 
49+             if ( this . isExternalFilter ) 
50+             { 
51+                 this . externalFilterPillsVals [ this . localFilterKey ]  =  [ ] ; 
52+                 this . displayString  =  this . generateLocalFilterPillImplodedValues ( this . externalFilterPillsVals [ this . localFilterKey ] ) ;  
53+                 this . updatePillHasValues ( ) ; 
54+                 this . resetSpecificFilter ( this . localFilterKey ) ; 
55+             } 
56+         } , 
57+         trigger : { 
58+             [ '@filterpillupdate.window' ] ( event )  { 
59+                 this . watchForUpdateEvent ( event ) ; 
60+             } , 
61+         } , 
62+         checkEventIsValid ( eventTableName ,  eventFilterKey ) 
63+         { 
64+             return  ( ( this . tableName  ===  eventTableName )  &&  ( this . localFilterKey  ===  eventFilterKey ) ) ; 
65+         } , 
66+         watchForUpdateEvent ( event ) 
67+         { 
68+             if ( this . checkEventIsValid ( event . detail . tableName  ??  '' ,  event . detail . filterKey  ??  '' ) ) 
69+             { 
70+                 let  eventPillItem  =  event . detail . pillItem  ??  '' ; 
71+                 if ( ! this . shouldRenderAsHTML ) 
72+                 { 
73+                     eventPillItem  =  this . removeHTMLTags ( eventPillItem ) ; 
74+                 } 
75+     
76+                 if ( eventPillItem  !=  "" ) 
77+                 { 
78+                     if ( this . isExternalFilter ) 
79+                     { 
80+                         let  filterPillValues  =  this . externalFilterPillsVals [ this . localFilterKey ] ; 
81+     
82+                         filterPillValues . push ( eventPillItem ) ; 
83+                         this . updatePillValues ( filterPillValues ) ; 
84+                     } 
85+                     else 
86+                     { 
87+                         this . updatePillValues ( eventPillItem ) ; 
88+                     }     
89+                 } 
90+             } 
91+         } , 
92+         updatePillValues ( filterPillValues ) 
93+         { 
94+             this . pillValues  =  filterPillValues ; 
95+             this . displayString  =  this . generateLocalFilterPillImplodedValues ( filterPillValues ) ;  
96+             this . updatePillHasValues ( ) ; 
97+ 
98+             return  this . displayString ; 
99+         } , 
100+         updatePillHasValues ( ) 
101+         { 
102+             this . pillHasValues  =  ( this . displayString . length  >  0 ) ; 
103+         } , 
104+         init ( ) 
105+         { 
106+             this . localFilterKey  =  this . localData [ 'filterKey' ]  ??  'unknown' ; 
107+             this . localFilterTitle  =  this . localData [ 'filterPillTitle' ]  ??  'Unknown' ; 
108+             this . pillsSeparator  =  this . localData [ 'separator' ]  ??  ',' ; 
109+             this . shouldWatchPillValues  =  Boolean ( this . localData [ 'watchForEvents' ]  ??  0 ) ; 
110+             this . isExternalFilter  =  Boolean ( this . localData [ 'isAnExternalLivewireFilter' ]  ??  0 ) ; 
111+             this . shouldRenderAsHTML  =  Boolean ( this . localData [ 'renderPillsAsHtml' ]  ??  0 ) ; 
112+             this . pillValues  =  this . localData [ 'pillValues' ]  ??  null ; 
113+ 
114+             this . $nextTick ( ( )  =>  {  
115+                 if ( this . isExternalFilter ) 
116+                 { 
117+                     this . updatePillValues ( this . externalFilterPillsVals [ this . localFilterKey ] ) ; 
118+                 } 
119+                 else 
120+                 { 
121+                     this . updatePillValues ( this . pillValues ) ; 
122+                 } 
123+             } ) ; 
124+             if ( this . isExternalFilter  &&  this . shouldWatchPillValues ) 
125+             { 
126+                 this . $watch ( 'externalFilterPillsVals.' + this . localFilterKey ,  filterPillValues  =>  {  
127+                     this . updatePillValues ( filterPillValues ) ; 
128+                 } ) ;       
129+             } 
130+         } 
131+     } ) ) ; 
132+ 
133+ } 
134+ 
135+ export  default  filterPills ; 
0 commit comments