"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.hasParentHeading = void 0;
exports.headingRule = headingRule;
// @ts-ignore // TODO: fix cjs build
const prosemirror_utils_1 = require("prosemirror-utils");
const inputrules_1 = require("../../../utils/inputrules.js");
const HeadingSpecs_1 = require("./HeadingSpecs/index.js");
const const_1 = require("./const.js");
const hasParentHeading = (level) => (state) => (0, prosemirror_utils_1.hasParentNode)((node) => {
    return node.type === (0, HeadingSpecs_1.headingType)(state.schema) && node.attrs[const_1.headingLevelAttr] === level;
})(state.selection);
exports.hasParentHeading = hasParentHeading;
// Given a node type and a maximum level, creates an input rule that
// turns up to that number of `#` characters followed by a space at
// the start of a textblock into a heading whose level corresponds to
// the number of `#` signs.
function headingRule(nodeType, maxLevel) {
    return (0, inputrules_1.textblockTypeInputRule)(new RegExp('^(#{1,' + maxLevel + '})\\s$'), nodeType, (match) => ({ [const_1.headingLevelAttr]: match[1].length }));
}
//# sourceMappingURL=utils.js.map
