import { DIPLODOC_ID_ATTR, YFM_TAB_CLASSNAME, tabPanelType } from "./const.js";
export const execAfterPaint = (fn) => {
    requestAnimationFrame(() => {
        requestAnimationFrame(fn);
    });
};
export const atEndOfPanel = (view) => {
    if (!view)
        return null;
    const { $head } = view.state.selection;
    for (let d = $head.depth; d >= 0; d--) {
        const parent = $head.node(d), index = $head.indexAfter(d);
        if (index !== parent.childCount)
            return false;
        if (parent.type === tabPanelType(view.state.schema)) {
            const panelPos = $head.before(d);
            return view?.endOfTextblock('down') ? panelPos : null;
        }
    }
    return null;
};
export const switchTabByElem = (tabElem) => {
    if (tabElem.classList.contains(YFM_TAB_CLASSNAME)) {
        tabElem.click();
    }
};
export const switchTabById = (container, tabId) => {
    const selector = `.${YFM_TAB_CLASSNAME}[${DIPLODOC_ID_ATTR}="${tabId}"]`;
    const tabElem = container.querySelector(selector);
    if (tabElem) {
        switchTabByElem(tabElem);
    }
};
//# sourceMappingURL=utils.js.map
