Skip to content

Commit 10197be

Browse files
committed
update doc comments
1 parent 86c9d52 commit 10197be

File tree

2 files changed

+95
-3
lines changed

2 files changed

+95
-3
lines changed

jsEngine/api/PromptAPI.ts

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,29 @@ export class PromptAPI {
7878
/**
7979
* Prompts the user with a modal containing a list of buttons.
8080
* Returns the value of the button that was clicked, or undefined if the modal was closed.
81+
*
82+
* @example
83+
* ```typescript
84+
* // Prompt the user with a true/false question.
85+
*
86+
* const ret = await engine.prompt.button({
87+
* title: 'The set of natural numbers with zero and the addition operation is a monoid.',
88+
* buttons: [
89+
* {
90+
* label: 'True',
91+
* value: true,
92+
* },
93+
* {
94+
* label: 'False',
95+
* value: false,
96+
* },
97+
* {
98+
* label: 'Cancel',
99+
* value: undefined,
100+
* }
101+
* ]
102+
* });
103+
* ```
81104
*/
82105
public button<T>(options: ButtonPromptOptions<T>): Promise<T | undefined> {
83106
return new Promise<T | undefined>((resolve, reject) => {
@@ -105,6 +128,16 @@ export class PromptAPI {
105128
/**
106129
* Prompts the user with a confirm/cancel dialog.
107130
* Returns true if the user confirms, false if the user cancels or otherwise closes the modal.
131+
*
132+
* @example
133+
* ```typescript
134+
* // Ask the user if they want to confirm an action.
135+
*
136+
* const ret = await engine.prompt.confirm({
137+
* title: 'Confirm File Deletion',
138+
* content: 'Are you sure you want to delete this file? This action cannot be undone.',
139+
* });
140+
* ```
108141
*/
109142
public async confirm(options: ConfirmPromptOptions): Promise<boolean> {
110143
return (
@@ -129,6 +162,15 @@ export class PromptAPI {
129162
/**
130163
* Prompts the user with a yes/no dialog.
131164
* Returns true if the user selects yes, false if the user selects no, and undefined if the user otherwise closes the modal.
165+
*
166+
* @example
167+
* ```typescript
168+
* // Ask the user if they like Obsidian.
169+
*
170+
* const ret = await engine.prompt.yesNo({
171+
* title: 'Is this a test?',
172+
* content: 'Are you sure this is a test? Are you sure that your choice is really meaningless?',
173+
* });
132174
*/
133175
public async yesNo(options: YesNoPromptOptions): Promise<boolean | undefined> {
134176
return await this.button<boolean>({
@@ -151,6 +193,23 @@ export class PromptAPI {
151193
/**
152194
* Prompts the user with a fuzzy finder suggester dialog.
153195
* Returns the value of the selected option, or undefined if the user closes the modal.
196+
*
197+
* @example
198+
* ```typescript
199+
* // Query a list of files and prompt the user to select one.
200+
*
201+
* const files = engine.query.files((file) => {
202+
* return {
203+
* label: file.name,
204+
* value: file.pat,
205+
* };
206+
* });
207+
*
208+
* const ret = await engine.prompt.suggester({
209+
* placeholder: 'Select a file',
210+
* options: files,
211+
* });
212+
* ```
154213
*/
155214
public suggester<T>(options: SuggesterPromptOptions<T>): Promise<T | undefined> {
156215
return new Promise<T | undefined>((resolve, reject) => {
@@ -165,6 +224,15 @@ export class PromptAPI {
165224
/**
166225
* Prompts the user with a text input dialog.
167226
* Returns the value of the input field, or undefined if the user closes the modal.
227+
*
228+
* @example
229+
* ```typescript
230+
* // Prompt the user to input their name.
231+
*
232+
* const ret = await engine.prompt.text({
233+
* title: 'Please enter your name',
234+
* content: 'Please enter your name in the field below.',
235+
* });
168236
*/
169237
public text(options: InputPromptOptions): Promise<string | undefined> {
170238
return new Promise<string | undefined>((resolve, reject) => {
@@ -193,6 +261,17 @@ export class PromptAPI {
193261
/**
194262
* Prompts the user with a textarea input dialog.
195263
* Returns the value of the input field, or undefined if the user closes the modal.
264+
*
265+
* @example
266+
* ```typescript
267+
* // Prompt the user to input a multi-line message.
268+
*
269+
* const ret = await engine.prompt.textarea({
270+
* title: 'Please enter your message',
271+
* content: 'Please enter your message in the field below.',
272+
* placeholder: 'Your message here...',
273+
* });
274+
* ```
196275
*/
197276
public textarea(options: InputPromptOptions): Promise<string | undefined> {
198277
return new Promise<string | undefined>((resolve, reject) => {
@@ -221,6 +300,16 @@ export class PromptAPI {
221300
/**
222301
* Prompts the user with a number input dialog.
223302
* Returns the value of the input field, or undefined if the user closes the modal.
303+
*
304+
* @example
305+
* ```typescript
306+
* // Prompt the user to input their age.
307+
*
308+
* const ret = await engine.prompt.text({
309+
* title: 'Please enter your age',
310+
* content: 'Please enter your age in years in the field below.',
311+
* });
312+
* ```
224313
*/
225314
public number(options: InputPromptOptions): Promise<number | undefined> {
226315
return new Promise<number | undefined>((resolve, reject) => {

jsEngine/api/QueryAPI.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ export class QueryAPI {
1111
/**
1212
* This function will run the `query` callback on every markdown file in the vault and then return a list of the results, with `undefined` filtered out.
1313
*
14-
* @example Find all markdown `TFiles` that start with the word "Foo":
14+
* @example
1515
* ```typescript
16+
* // Find all markdown `TFiles` that start with the word "Foo"
1617
* const files = engine.query.files(file => file.name.startsWith("Foo") ? file : undefined);
1718
* ```
1819
*
19-
* @example Find all the names of all markdown files that are in the "Foo" folder:
20+
* @example
2021
* ```typescript
22+
* // Find all the names of all markdown files that are in the "Foo" folder
2123
* const fileNames = engine.query.files(file => file.path.startsWith("Foo/") ? file.name : undefined);
2224
* ```
2325
*/
@@ -31,8 +33,9 @@ export class QueryAPI {
3133
/**
3234
* This function functions similarly tp {@link QueryAPI.files}, but also provides the cache and tags of each file to the `query` callback.
3335
*
34-
* @example Find the paths of all markdown files that have the tag "Foo":
36+
* @example
3537
* ```typescript
38+
* // Find the paths of all markdown files that have the tag "Foo"
3639
* const paths = engine.query.filesWithMetadata((file, cache, tags) => tags.includes("Foo") ? file.path : undefined);
3740
* ```
3841
*/

0 commit comments

Comments
 (0)