import { UNSUPPORTED_MOBILE_TEMPLATE } from "utils/Constants" ; import { InternalModule } from "../InternalModule" ; import { Platform } from "obsidian" ; import { PromptModal } from "./PromptModal" ; import { SuggesterModal } from "./SuggesterModal" ; import { TemplaterError } from "utils/Error" ; import { ModuleName } from "editor/TpDocumentation" ; export class InternalModuleSystem extends InternalModule { public name : ModuleName = "system" ; async create_static_templates ( ) { this . static_functions . set ( "clipboard" , this . generate_clipboard ( ) ) ; this . static_functions . set ( "prompt" , this . generate_prompt ( ) ) ; this . static_functions . set ( "suggester" , this . generate_suggester ( ) ) ; } async create_dynamic_templates ( ) { } generate_clipboard ( ) { return async ( ) => { if ( Platform . isMobileApp ) { return UNSUPPORTED_MOBILE_TEMPLATE ; } return await navigator . clipboard . readText ( ) ; } ; } generate_prompt ( ) { return async ( prompt_text , default_value , throw_on_cancel = false ) : Promise < string > => { const prompt = new PromptModal ( this . app , prompt_text , default_value ) ; const promise = new Promise ( ( resolve , reject ) => prompt . openAndGetValue ( resolve , reject ) ) ; try { return await promise ; } catch ( error ) { if ( throw_on_cancel ) { throw error ; } return null ; } } ; } generate_suggester ( ) { return async < T > ( text_items , items , throw_on_cancel = false , placeholder = "" ) : Promise < T > => { const suggester = new SuggesterModal ( this . app , text_items , items , placeholder ) ; const promise = new Promise ( ( resolve , reject ) => suggester . openAndGetValue ( resolve , reject ) ) ; try { return await promise ; } catch ( error ) { if ( throw_on_cancel ) { throw error ; } return null ; } } ; } }