@@ -372,7 +372,7 @@ function sqlpage_form() {
372372 }
373373}
374374
375- function get_tabler_color ( name ) {
375+ function get_tabler_color ( name : string ) {
376376 return getComputedStyle ( document . documentElement ) . getPropertyValue (
377377 `--tblr-${ name } ` ,
378378 ) ;
@@ -394,16 +394,16 @@ function load_scripts() {
394394 }
395395}
396396
397- function normalize_hash ( hash ) {
398- const normalized = hash ?. replace ( / ^ # / , "" ) ;
397+ function normalize_hash ( hash : string | undefined ) {
398+ const normalized = hash ?. replace ( / ^ # / , "" ) ?? "" ;
399399 try {
400400 return decodeURIComponent ( normalized ) ;
401401 } catch {
402402 return normalized ;
403403 }
404404}
405405
406- function open_toasts_for_hash ( toasts ) {
406+ function open_toasts_for_hash ( toasts : Iterable < HTMLElement > ) {
407407 const Toast = page_bootstrap ( ) . Toast ;
408408 const hash = normalize_hash ( window . location . hash ) ;
409409 if ( ! hash ) return ;
@@ -414,9 +414,9 @@ function open_toasts_for_hash(toasts) {
414414 }
415415}
416416
417- function restore_focus_after_toast ( toast , container ) {
417+ function restore_focus_after_toast ( toast : HTMLElement , container : HTMLElement ) {
418418 if ( ! toast . contains ( document . activeElement ) ) return ;
419- const next_close = container . querySelector (
419+ const next_close = container . querySelector < HTMLElement > (
420420 '.toast.show [data-bs-dismiss="toast"]' ,
421421 ) ;
422422 if ( next_close ) {
@@ -501,27 +501,39 @@ add_init_fn(sqlpage_modal);
501501add_init_fn ( load_scripts ) ;
502502add_init_fn ( sqlpage_toast ) ;
503503window . addEventListener ( "hashchange" , ( ) =>
504- open_toasts_for_hash ( document . querySelectorAll ( "[data-toast-trigger]" ) ) ,
504+ open_toasts_for_hash (
505+ document . querySelectorAll < HTMLElement > ( "[data-toast-trigger]" ) ,
506+ ) ,
505507) ;
506508
507- function init_bootstrap_components ( event ) {
509+ function init_bootstrap_components ( fragment : Element | Document ) {
508510 const bootstrap = page_bootstrap ( ) ;
509- const fragment = event . target ;
510- for ( const el of fragment . querySelectorAll ( '[data-bs-toggle="tooltip"]' ) ) {
511+ for ( const el of fragment . querySelectorAll < HTMLElement > (
512+ '[data-bs-toggle="tooltip"]' ,
513+ ) ) {
511514 new bootstrap . Tooltip ( el ) ;
512515 }
513- for ( const el of fragment . querySelectorAll ( '[data-bs-toggle="popover"]' ) ) {
516+ for ( const el of fragment . querySelectorAll < HTMLElement > (
517+ '[data-bs-toggle="popover"]' ,
518+ ) ) {
514519 new bootstrap . Popover ( el ) ;
515520 }
516- for ( const el of fragment . querySelectorAll ( '[data-bs-toggle="dropdown"]' ) ) {
521+ for ( const el of fragment . querySelectorAll < HTMLElement > (
522+ '[data-bs-toggle="dropdown"]' ,
523+ ) ) {
517524 new bootstrap . Dropdown ( el ) ;
518525 }
519- for ( const el of fragment . querySelectorAll ( '[data-bs-ride="carousel"]' ) ) {
526+ for ( const el of fragment . querySelectorAll < HTMLElement > (
527+ '[data-bs-ride="carousel"]' ,
528+ ) ) {
520529 new bootstrap . Carousel ( el ) ;
521530 }
522531}
523532
524- document . addEventListener ( "fragment-loaded" , init_bootstrap_components ) ;
533+ document . addEventListener ( "fragment-loaded" , ( { target } ) => {
534+ if ( target instanceof Element || target instanceof Document )
535+ init_bootstrap_components ( target ) ;
536+ } ) ;
525537
526538function open_modal_for_hash ( ) {
527539 const hash = window . location . hash . substring ( 1 ) ;
0 commit comments