@@ -7,7 +7,7 @@ import { Datacore } from "index/datacore";
77import { SearchResult } from "index/datastore" ;
88import { IndexQuery } from "index/types/index-query" ;
99import { Indexable } from "index/types/indexable" ;
10- import { MarkdownPage } from "index/types/markdown" ;
10+ import { MarkdownPage , MarkdownTaskItem } from "index/types/markdown" ;
1111import { App } from "obsidian" ;
1212import { useAsync , useFileMetadata , useFullQuery , useIndexUpdates , useInterning , useQuery } from "ui/hooks" ;
1313import * as luxon from "luxon" ;
@@ -31,13 +31,16 @@ import { Literal } from "expression/literal";
3131import { Button , Checkbox , Icon , Slider , Switch , Textbox , VanillaSelect } from "./ui/basics" ;
3232import { VanillaTable } from "./ui/views/table" ;
3333import { Callout } from "./ui/views/callout" ;
34+ import { TaskList } from "./ui/views/task" ;
35+ import { Card } from "./ui/views/cards" ;
3436import { DataArray } from "./data-array" ;
3537import { Coerce } from "./coerce" ;
3638import { ScriptCache } from "./script-cache" ;
3739import { Expression } from "expression/expression" ;
38- import { Card } from "./ui/views/cards" ;
3940import { ControlledEditable } from "ui/fields/editable" ;
40- import { TaskList } from "./ui/views/task" ;
41+ import { setTaskText , useSetField } from "utils/fields" ;
42+ import { ControlledEditableTextField , EditableFieldCheckbox , EditableTextField } from "ui/fields/editable-fields" ;
43+ import { completeTask } from "utils/task" ;
4144import { ListView } from "./ui/views/list" ;
4245
4346/** Local API provided to specific codeblocks when they are executing.
@@ -178,6 +181,16 @@ export class DatacoreLocalApi {
178181 return this . api . tryEvaluate ( expression , variables , sourcePath ?? this . path ) ;
179182 }
180183
184+ /** Sets the text of a given task programmatically. */
185+ public setTaskText ( newText : string , task : MarkdownTaskItem ) : void {
186+ setTaskText ( this . app , this . core , newText , task ) ;
187+ }
188+
189+ /** Sets the completion status of a given task programmatically. */
190+ public setTaskCompletion ( completed : boolean , task : MarkdownTaskItem ) : void {
191+ completeTask ( completed , task , this . app . vault , this . core ) ;
192+ }
193+
181194 //////////////
182195 // Contexts //
183196 //////////////
@@ -213,6 +226,7 @@ export class DatacoreLocalApi {
213226 public useRef = hooks . useRef ;
214227 public useInterning = useInterning ;
215228 public useAsync = useAsync ;
229+ public useSetField = useSetField ;
216230
217231 /** Memoize the input automatically and process it using a DataArray; returns a vanilla array back. */
218232 public useArray < T , U > ( input : T [ ] | DataArray < T > , process : ( data : DataArray < T > ) => DataArray < U > , deps ?: any [ ] ) : U [ ] {
@@ -393,4 +407,11 @@ export class DatacoreLocalApi {
393407 public Slider = Slider ;
394408 public Switch = Switch ;
395409 public VanillaSelect = VanillaSelect ;
410+
411+ /////////////////////////
412+ // field editors //
413+ /////////////////////////
414+ public EditableFieldCheckbox = EditableFieldCheckbox ;
415+ public EditableFieldTextbox = EditableTextField ;
416+ public TextEditor = ControlledEditableTextField ;
396417}
0 commit comments