import { newlineInCode, setBlockType } from 'prosemirror-commands';
import { toParagraph } from "../../base/BaseSchema/index.js";
import { codeBlockType } from "./const.js";
export { newlineInCode };
export const resetCodeblock = (state, dispatch, view) => {
    const { selection } = state;
    if (selection.empty &&
        selection.$from.parent.type === codeBlockType(state.schema) &&
        view?.endOfTextblock('backward', state)) {
        return toParagraph(state, dispatch, view);
    }
    return false;
};
export const setCodeBlockType = ({ serializer }) => (state, dispatch) => {
    const nodeType = codeBlockType(state.schema);
    if (!setBlockType(nodeType)(state))
        return false;
    if (dispatch) {
        // FIXME: Verify and use Node instead of Fragment
        const markup = serializer.serialize(state.selection.content().content, {
            escape: false,
        });
        dispatch(state.tr.replaceSelectionWith(nodeType.createAndFill({}, markup ? state.schema.text(markup) : null)));
    }
    return true;
};
//# sourceMappingURL=commands.js.map
