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