import { setBlockType } from "../../../pm/commands.js";
import { findParentNodeOfType } from "../../../pm/utils.js";
import { toParagraph } from "../../base/BaseSchema/index.js";
import { headingLevelAttr, headingType } from "./HeadingSpecs/index.js";
export const resetHeading = (state, dispatch, view) => {
    const { selection } = state;
    if (selection.empty &&
        selection.$from.parent.type === headingType(state.schema) &&
        view?.endOfTextblock('backward', state)) {
        return toParagraph(state, dispatch, view);
    }
    return false;
};
export const toHeading = (level) => (state, dispatch, view) => {
    const attrs = {};
    const parentHeading = findParentNodeOfType(headingType(state.schema))(state.selection);
    if (parentHeading) {
        if (parentHeading.node.attrs[headingLevelAttr] === level) {
            return toParagraph(state, dispatch, view);
        }
        Object.assign(attrs, parentHeading.node.attrs);
    }
    attrs[headingLevelAttr] = level;
    return setBlockType(headingType(state.schema), attrs)(state, dispatch);
};
//# sourceMappingURL=commands.js.map
