Skip to content

Commit d43566d

Browse files
re-add setTaskText and setTaskCompletion utilities to local api
1 parent 3672315 commit d43566d

1 file changed

Lines changed: 24 additions & 3 deletions

File tree

src/api/local-api.tsx

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Datacore } from "index/datacore";
77
import { SearchResult } from "index/datastore";
88
import { IndexQuery } from "index/types/index-query";
99
import { Indexable } from "index/types/indexable";
10-
import { MarkdownPage } from "index/types/markdown";
10+
import { MarkdownPage, MarkdownTaskItem } from "index/types/markdown";
1111
import { App } from "obsidian";
1212
import { useAsync, useFileMetadata, useFullQuery, useIndexUpdates, useInterning, useQuery } from "ui/hooks";
1313
import * as luxon from "luxon";
@@ -31,13 +31,16 @@ import { Literal } from "expression/literal";
3131
import { Button, Checkbox, Icon, Slider, Switch, Textbox, VanillaSelect } from "./ui/basics";
3232
import { VanillaTable } from "./ui/views/table";
3333
import { Callout } from "./ui/views/callout";
34+
import { TaskList } from "./ui/views/task";
35+
import { Card } from "./ui/views/cards";
3436
import { DataArray } from "./data-array";
3537
import { Coerce } from "./coerce";
3638
import { ScriptCache } from "./script-cache";
3739
import { Expression } from "expression/expression";
38-
import { Card } from "./ui/views/cards";
3940
import { 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";
4144
import { 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

Comments
 (0)