@@ -23,6 +23,7 @@ jQuery(document).ready(function ($) {
2323 let currentTaxonomy = '' ;
2424 let availablePostTypes = { } ;
2525 let isCreating = false ;
26+ let slimSelects = { } ; // Track SS instances by row ID
2627 const i18n = wbpgData . i18n ;
2728
2829 // Theme Toggle Logic
@@ -187,12 +188,36 @@ jQuery(document).ready(function ($) {
187188 }
188189 }
189190
191+ function initSlimSelect ( $select , rowId ) {
192+ if ( typeof SlimSelect !== 'function' ) return ;
193+
194+ // Destroy existing instance if it exists
195+ if ( slimSelects [ rowId ] ) {
196+ slimSelects [ rowId ] . destroy ( ) ;
197+ }
198+
199+ slimSelects [ rowId ] = new SlimSelect ( {
200+ select : $select [ 0 ] ,
201+ settings : {
202+ placeholderText : i18n . search || 'Search...' ,
203+ searchText : i18n . no_results || 'No results found' ,
204+ searchHighlight : true
205+ }
206+ } ) ;
207+ }
208+
190209 function refreshDropdowns ( ) {
191210 $ ( '.wbpg-row .wbpg-row-parent' ) . each ( function ( ) {
192211 const $select = $ ( this ) ;
193- if ( $select . closest ( 'tr' ) . find ( '.wbpg-status-icon' ) . hasClass ( 'pending' ) ) {
212+ const $row = $select . closest ( 'tr' ) ;
213+ const rowId = $row . attr ( 'id' ) ;
214+
215+ if ( $row . find ( '.wbpg-status-icon' ) . hasClass ( 'pending' ) ) {
194216 const currentVal = $select . val ( ) ;
195217 $select . html ( parentOptionsHtml ) . val ( currentVal ) ;
218+
219+ // Re-init SlimSelect if hierarchy changed
220+ initSlimSelect ( $select , rowId ) ;
196221 }
197222 } ) ;
198223 }
@@ -218,9 +243,12 @@ jQuery(document).ready(function ($) {
218243 $this . val ( currentPostType ) ;
219244 return ;
220245 }
221- $rowsContainer . empty ( ) ;
222246 $listWrapper . hide ( ) ;
223247 $summaryBox . hide ( ) ;
248+
249+ // Clear all SS instances
250+ Object . values ( slimSelects ) . forEach ( ss => ss . destroy ( ) ) ;
251+ slimSelects = { } ;
224252 }
225253
226254 currentPostType = val ;
@@ -268,6 +296,14 @@ jQuery(document).ready(function ($) {
268296 fragment . appendChild ( tempTbody . firstChild ) ;
269297 }
270298 $rowsContainer [ 0 ] . appendChild ( fragment ) ;
299+
300+ // Batch initialize SlimSelect for performance
301+ $rowsContainer . find ( '.wbpg-row-parent' ) . each ( function ( ) {
302+ const $select = $ ( this ) ;
303+ const rowId = $select . closest ( 'tr' ) . attr ( 'id' ) ;
304+ initSlimSelect ( $select , rowId ) ;
305+ } ) ;
306+
271307 initTooltips ( ) ; // Re-init for new icons
272308
273309 $listWrapper . show ( ) ;
@@ -331,7 +367,13 @@ jQuery(document).ready(function ($) {
331367 if ( selected . length === 0 ) return ;
332368
333369 if ( confirm ( i18n . confirm_remove . replace ( '%d' , selected . length ) ) ) {
334- selected . closest ( 'tr' ) . fadeOut ( 300 , function ( ) {
370+ selected . closest ( 'tr' ) . each ( function ( ) {
371+ const rowId = $ ( this ) . attr ( 'id' ) ;
372+ if ( slimSelects [ rowId ] ) {
373+ slimSelects [ rowId ] . destroy ( ) ;
374+ delete slimSelects [ rowId ] ;
375+ }
376+ } ) . fadeOut ( 300 , function ( ) {
335377 $ ( this ) . remove ( ) ;
336378 toggleBulkActions ( ) ;
337379 if ( $ ( '.wbpg-row' ) . length === 0 ) {
@@ -346,7 +388,14 @@ jQuery(document).ready(function ($) {
346388 $rowsContainer . on ( 'click keydown' , '.wbpg-row-remove' , function ( e ) {
347389 if ( e . type === 'keydown' && e . key !== 'Enter' && e . key !== ' ' ) return ;
348390
349- $ ( this ) . closest ( 'tr' ) . fadeOut ( 300 , function ( ) {
391+ const $row = $ ( this ) . closest ( 'tr' ) ;
392+ const rowId = $row . attr ( 'id' ) ;
393+
394+ $row . fadeOut ( 300 , function ( ) {
395+ if ( slimSelects [ rowId ] ) {
396+ slimSelects [ rowId ] . destroy ( ) ;
397+ delete slimSelects [ rowId ] ;
398+ }
350399 $ ( this ) . remove ( ) ;
351400 toggleBulkActions ( ) ;
352401 if ( $ ( '.wbpg-row' ) . length === 0 ) {
@@ -528,12 +577,12 @@ jQuery(document).ready(function ($) {
528577 $ ( '#wbpg-results-container' ) . hide ( ) ;
529578 $ ( '#wbpg-start-over-btn' ) . hide ( ) ;
530579
531- // Reset Table
532- $rowsContainer . empty ( ) ;
533- $listWrapper . hide ( ) ;
534- $ ( '#wbpg-select-all' ) . prop ( 'checked' , false ) ;
535580 $ ( '#wbpg-delete-selected-btn' ) . hide ( ) ;
536581
582+ // Clear all SS instances
583+ Object . values ( slimSelects ) . forEach ( ss => ss . destroy ( ) ) ;
584+ slimSelects = { } ;
585+
537586 // Reset selection
538587 $ ( '#wbpg-post-type' ) . val ( '' ) ;
539588 $ ( '#wbpg-generate-row' ) . hide ( ) ;
0 commit comments