import { Plugin } from 'prosemirror-state';
import { addParagraphToEnd, addParagraphToStart } from "./commands.js";
const startActionName = 'addEmptyDefaultTextblockToStartOfDocument';
const endActionName = 'addEmptyDefaultTextblockToEndOfDocument';
export const ClicksOnEdges = (builder) => {
    builder.addAction(startActionName, () => ({
        isEnable: addParagraphToStart,
        run: addParagraphToStart,
    }));
    builder.addAction(endActionName, () => ({
        isEnable: addParagraphToEnd,
        run: addParagraphToEnd,
    }));
    builder.addPlugin(() => {
        return new Plugin({
            props: {
                handleClick(view, _pos, event) {
                    if (event.target !== view.dom)
                        return false;
                    const { firstChild, lastChild } = event.target;
                    if (!firstChild || !lastChild)
                        return false;
                    const targetRect = event.target.getBoundingClientRect();
                    const firstRect = firstChild.getBoundingClientRect();
                    const lastRect = lastChild.getBoundingClientRect();
                    const firstOffsetTop = firstRect.top - targetRect.y;
                    const lastOffsetBottom = lastRect.bottom - targetRect.y;
                    if (event.offsetY < firstOffsetTop) {
                        return addParagraphToStart(view.state, view.dispatch);
                    }
                    if (event.offsetY > lastOffsetBottom) {
                        return addParagraphToEnd(view.state, view.dispatch);
                    }
                    return false;
                },
            },
        });
    });
};
//# sourceMappingURL=ClicksOnEdges.js.map
