"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.QuoteLink = void 0;
require("@diplodoc/quote-link-extension/runtime");
// @ts-ignore // TODO: fix cjs build
const prosemirror_utils_1 = require("prosemirror-utils");
const extensions_1 = require("../../index.js");
const utils_1 = require("../../../utils/index.js");
const QuoteLinkSpecs_1 = require("./QuoteLinkSpecs/index.js");
const commands_1 = require("./commands.js");
require("./index.css");
require("@diplodoc/quote-link-extension/runtime/styles.css");
const quoteLinkAction = 'quoteLink';
const addLinkToQuoteLinkAction = 'addLinkToQuoteLink';
const QuoteLink = (builder) => {
    builder.use(QuoteLinkSpecs_1.QuoteLinkSpecs);
    builder.addInputRules(({ schema }) => ({
        rules: [quoteLinkInputRule((0, QuoteLinkSpecs_1.quoteLinkType)(schema))],
    }));
    builder.addAction(quoteLinkAction, ({ schema }) => {
        const quoteLink = (0, QuoteLinkSpecs_1.quoteLinkType)(schema);
        return {
            isActive: (state) => (0, prosemirror_utils_1.hasParentNodeOfType)(quoteLink)(state.selection),
            isEnable: commands_1.toggleQuote,
            run: commands_1.toggleQuote,
        };
    });
    builder.addAction(addLinkToQuoteLinkAction, (deps) => ({
        isActive: (state) => Boolean((0, utils_1.isMarkActive)(state, (0, extensions_1.linkType)(state.schema))),
        isEnable: (0, commands_1.addQuoteLink)(deps),
        run: (0, commands_1.addQuoteLink)(deps),
    }));
};
exports.QuoteLink = QuoteLink;
/**
 * Given a quoteLink node type, returns an input rule that turns `"> "`
 * at the start of a textblock into a quoteLink.
 */
function quoteLinkInputRule(nodeType) {
    return (0, utils_1.wrappingInputRule)(/^\s*>\s$/, nodeType);
}
//# sourceMappingURL=index.js.map
