Files
outline/shared/editor/commands/toggleCheckboxItem.ts
Tom Moor bf45e97641 chore: Enforce type import consistency (#10968)
* Update types

* fix circular dep

* type imports

* lint type imports and --fix
2025-12-19 23:07:02 -05:00

35 lines
849 B
TypeScript

import type { Command } from "prosemirror-state";
import { findParentNode } from "../queries/findParentNode";
/**
* A prosemirror command to toggle the checkbox item at the current selection.
*
* @returns A prosemirror command.
*/
export default function toggleCheckboxItem(): Command {
return (state, dispatch) => {
const { empty } = state.selection;
// if the selection has anything in it then use standard behavior
if (!empty) {
return false;
}
// check we're in a matching node
const listItem = findParentNode(
(node) => node.type === state.schema.nodes.checkbox_item
)(state.selection);
if (!listItem) {
return false;
}
dispatch?.(
state.tr.setNodeMarkup(listItem.pos, undefined, {
checked: !listItem.node.attrs.checked,
})
);
return true;
};
}