import { setBlockType } from 'prosemirror-commands';
// @ts-ignore // TODO: fix cjs build
import { findParentNodeOfType } from 'prosemirror-utils';
import { toParagraph } from "../../base/index.js";
import { headingType } from "./YfmHeadingSpecs/utils.js";
import { YfmHeadingAttr, headingLevelAttr } from "./const.js";
export { resetHeading } from "../../markdown/Heading/commands.js";
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);
    }
    // const text = state.selection.$head.parent.textContent;
    // attrs[YfmHeadingAttr.Id] = slugify(text);
    attrs[YfmHeadingAttr.Level] = level;
    return setBlockType(headingType(state.schema), attrs)(state, dispatch);
};
//# sourceMappingURL=commands.js.map
