@atlaskit/editor-plugin-tasks-and-decisions
Version:
Tasks and decisions plugin for @atlaskit/editor-core
23 lines • 965 B
JavaScript
export function taskItemOnChange(view, event) {
var _parentNode$type;
const {
target
} = event;
if (!target || !(target instanceof HTMLInputElement) || target.type !== 'checkbox' || target.getAttribute('data-input-type') !== 'lazy-task-item') {
return;
}
const pos = view.posAtDOM(target, 0);
// Resolve the position in the current document
const resolvedPos = view.state.doc.resolve(pos);
// Access the parent node
const parentNode = resolvedPos === null || resolvedPos === void 0 ? void 0 : resolvedPos.parent;
if ((parentNode === null || parentNode === void 0 ? void 0 : (_parentNode$type = parentNode.type) === null || _parentNode$type === void 0 ? void 0 : _parentNode$type.name) !== 'taskItem') {
return;
}
const parentPos = resolvedPos.before(resolvedPos.depth);
const tr = view.state.tr.setNodeMarkup(parentPos, null, {
...parentNode.attrs,
state: target.checked ? 'DONE' : 'TODO'
});
view.dispatch(tr);
}