@@ -2,6 +2,7 @@ import type { API } from 'jsEngine/api/API';
22import { ButtonStyleType } from 'jsEngine/utils/Util' ;
33import { SvelteModal } from 'jsEngine/api/prompts/SvelteModal' ;
44import ButtonModalComponent from 'jsEngine/api/prompts/ButtonModalComponent.svelte' ;
5+ import InputModalComponent from 'jsEngine/api/prompts/InputModalComponent.svelte' ;
56import { Suggester } from 'jsEngine/api/prompts/Suggester' ;
67import { mount } from 'svelte' ;
78import type { AnySvelteComponent } from 'jsEngine/utils/SvelteUtils' ;
@@ -56,6 +57,17 @@ export interface SuggesterOption<T> {
5657 label : string ;
5758}
5859
60+ export interface InputPromptOptions extends ModalPromptOptions {
61+ /**
62+ * Text content to display in the modal.
63+ */
64+ content ?: string ;
65+ /**
66+ * The placeholder text for the input field.
67+ */
68+ placeholder ?: string ;
69+ }
70+
5971export class PromptAPI {
6072 readonly apiInstance : API ;
6173
@@ -149,4 +161,88 @@ export class PromptAPI {
149161 }
150162 } ) ;
151163 }
164+
165+ /**
166+ * Prompts the user with a text input dialog.
167+ * Returns the value of the input field, or undefined if the user closes the modal.
168+ */
169+ public text ( options : InputPromptOptions ) : Promise < string | undefined > {
170+ return new Promise < string | undefined > ( ( resolve , reject ) => {
171+ try {
172+ new SvelteModal < AnySvelteComponent , unknown > (
173+ this . apiInstance . app ,
174+ options ,
175+ ( modal , targetEl ) => {
176+ return mount ( InputModalComponent , {
177+ target : targetEl ,
178+ props : {
179+ options,
180+ modal,
181+ inputType : 'text' ,
182+ } ,
183+ } ) ;
184+ } ,
185+ resolve as ( value : unknown ) => void ,
186+ ) . open ( ) ;
187+ } catch ( error ) {
188+ reject ( error ) ;
189+ }
190+ } ) ;
191+ }
192+
193+ /**
194+ * Prompts the user with a textarea input dialog.
195+ * Returns the value of the input field, or undefined if the user closes the modal.
196+ */
197+ public textarea ( options : InputPromptOptions ) : Promise < string | undefined > {
198+ return new Promise < string | undefined > ( ( resolve , reject ) => {
199+ try {
200+ new SvelteModal < AnySvelteComponent , unknown > (
201+ this . apiInstance . app ,
202+ options ,
203+ ( modal , targetEl ) => {
204+ return mount ( InputModalComponent , {
205+ target : targetEl ,
206+ props : {
207+ options,
208+ modal,
209+ inputType : 'textarea' ,
210+ } ,
211+ } ) ;
212+ } ,
213+ resolve as ( value : unknown ) => void ,
214+ ) . open ( ) ;
215+ } catch ( error ) {
216+ reject ( error ) ;
217+ }
218+ } ) ;
219+ }
220+
221+ /**
222+ * Prompts the user with a number input dialog.
223+ * Returns the value of the input field, or undefined if the user closes the modal.
224+ */
225+ public number ( options : InputPromptOptions ) : Promise < number | undefined > {
226+ return new Promise < number | undefined > ( ( resolve , reject ) => {
227+ try {
228+ new SvelteModal < AnySvelteComponent , unknown > (
229+ this . apiInstance . app ,
230+ options ,
231+ ( modal , targetEl ) => {
232+ return mount ( InputModalComponent , {
233+ target : targetEl ,
234+ props : {
235+ options,
236+ modal,
237+ inputType : 'number' ,
238+ } ,
239+ } ) ;
240+ } ,
241+ resolve as ( value : unknown ) => void ,
242+ ) . open ( ) ;
243+ } catch ( error ) {
244+ reject ( error ) ;
245+ }
246+ } ) ;
247+ }
152248}
0 commit comments