"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Blockquote = exports.blockquoteType = exports.blockquoteNodeName = void 0;
const prosemirror_commands_1 = require("prosemirror-commands");
// @ts-ignore // TODO: fix cjs build
const prosemirror_utils_1 = require("prosemirror-utils");
const inputrules_1 = require("../../../utils/inputrules.js");
const keymap_1 = require("../../../utils/keymap.js");
const BlockquoteSpecs_1 = require("./BlockquoteSpecs/index.js");
const commands_1 = require("./commands.js");
var const_1 = require("./const.js");
Object.defineProperty(exports, "blockquoteNodeName", { enumerable: true, get: function () { return const_1.blockquoteNodeName; } });
Object.defineProperty(exports, "blockquoteType", { enumerable: true, get: function () { return const_1.blockquoteType; } });
const bqAction = 'quote';
const Blockquote = (builder, opts) => {
    builder.use(BlockquoteSpecs_1.BlockquoteSpecs);
    if (opts?.qouteKey) {
        const { qouteKey } = opts;
        builder.addKeymap(({ schema }) => ({
            [qouteKey]: (0, keymap_1.withLogAction)('blockquote', (0, prosemirror_commands_1.wrapIn)((0, BlockquoteSpecs_1.blockquoteType)(schema))),
        }));
    }
    builder.addKeymap(() => ({
        Backspace: (0, prosemirror_commands_1.chainCommands)(commands_1.liftFromQuote, commands_1.joinPrevQuote),
    }));
    builder.addInputRules(({ schema }) => ({ rules: [blockQuoteRule((0, BlockquoteSpecs_1.blockquoteType)(schema))] }));
    builder.addAction(bqAction, ({ schema }) => {
        const bq = (0, BlockquoteSpecs_1.blockquoteType)(schema);
        return {
            isActive: (state) => (0, prosemirror_utils_1.hasParentNodeOfType)(bq)(state.selection),
            isEnable: commands_1.toggleQuote,
            run: commands_1.toggleQuote,
        };
    });
};
exports.Blockquote = Blockquote;
/**
 * Given a blockquote node type, returns an input rule that turns `"> "`
 * at the start of a textblock into a blockquote.
 */
function blockQuoteRule(nodeType) {
    return (0, inputrules_1.wrappingInputRule)(/^\s*>\s$/, nodeType);
}
//# sourceMappingURL=index.js.map
