import { assertExists } from '@blockeditor/global/utils';
function getNextSibling(std, blockElement, filter) {
    const view = std.view;
    const nextView = view.findNext(blockElement.path, node => {
        if (node.type !== 'block' || node.view.contains(blockElement)) {
            return;
        }
        if (filter && !filter(node.view)) {
            return;
        }
        return true;
    });
    if (!nextView)
        return null;
    return view.viewFromPath('block', nextView.path);
}
function getNextBlock(std, path, filter) {
    const view = std.view;
    const focusBlock = view.viewFromPath('block', path);
    if (!focusBlock)
        return null;
    let next = null;
    if (focusBlock.childBlockElements[0]) {
        next = focusBlock.childBlockElements[0];
    }
    if (!next) {
        next = getNextSibling(std, focusBlock, filter);
    }
    if (next && !next.contains(focusBlock)) {
        return next;
    }
    return null;
}
export const getNextBlockCommand = (ctx, next) => {
    const path = ctx.path ?? ctx.currentSelectionPath;
    assertExists(path, '`path` is required, you need to pass it in args or ctx before adding this command to the pipeline.');
    const nextBlock = getNextBlock(ctx.std, path, ctx.filter);
    if (nextBlock) {
        next({ nextBlock });
    }
};
//# sourceMappingURL=get-next-block.js.map