import { TemplaterError } from "utils/Error" ; import { App , FuzzyMatch , FuzzySuggestModal } from "obsidian" ; export class SuggesterModal < T > extends FuzzySuggestModal < T > { private resolve : ( value : T ) => void ; private reject : ( reason ? : TemplaterError ) => void ; private submitted = false ; constructor ( app , private text_items , private items , placeholder ) { super ( app ) ; this . setPlaceholder ( placeholder ) ; } getItems ( ) { return this . items ; } onClose ( ) { if ( ! this . submitted ) { this . reject ( new TemplaterError ( "Cancelled prompt" ) ) ; } } selectSuggestion ( value , evt ) { this . submitted = true ; this . close ( ) ; this . onChooseSuggestion ( value , evt ) ; } getItemText ( item ) { if ( this . text_items instanceof Function ) { return this . text_items ( item ) ; } return ( this . text_items [ this . items . indexOf ( item ) ] || "Undefined Text Item" ) ; } onChooseItem ( item ) { this . resolve ( item ) ; } async openAndGetValue ( resolve , reject ) { this . resolve = resolve ; this . reject = reject ; this . open ( ) ; } }