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