Todo Item

Todo list item (todo-item). Renders as <li> with checkbox and .todo-text editable region. JSON data: { content: string, done?: boolean, ...common }.

Type: todo-item · Class: TodoListItemBlock

Access:

app.block.get()
app.blocks.findByEl(el)
app.blocks.create(type)

App code:

const block = app.block.get();

Plugin:

const block = this.app.block.get();

getData#

Returns common fields plus serialized content and done: true when data-checked="1".

Returns: object

block.getData();

getNestedLists#

Returns direct child <ul> and <ol> elements nested under this item.

Returns: Array

block.getNestedLists();

hasNestedList#

Returns whether this item contains at least one nested list.

Returns: boolean

block.hasNestedList();

detachNestedLists#

Removes and returns all nested <ul>/<ol> elements from the item.

Returns: Array

const lists = block.detachNestedLists();

detachNestedListItems#

Extracts every nested <li> from child lists, removes the lists, and returns the detached items.

Returns: Array

const items = block.detachNestedListItems();

update#

Applies common fields, toggles checkbox/data-checked, and updates .todo-text from content (HTML) or text (plain text).

Parameters:

  • data (object) — object with the keys below
    • done (boolean) — checked state
    • content (string) — HTML for .todo-text
    • text (string) — plain text for .todo-text when content is omitted
    • id, classname, styles, attrs, … — common block fields (see Common update)

Returns: void

block.update({ done: true });

block.update({ content: '<em>Finished</em>' });

block.update({ done: true, content: '<em>Finished</em>' });

block.update({ text: 'Plain task label' });

getTopLevelListRoot#

Walks up from this block's element and returns the outermost <ul> or <ol> ancestor inside the editor (including nested lists).

Parameters:

  • editable (HTMLElement | null) — optional editor root that bounds the walk (defaults to app.host.getEditor())

Returns: HTMLElement | null

block.getTopLevelListRoot();
block.getTopLevelListRoot(app.host.getEditor());