"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ClicksOnEdges = void 0;
const prosemirror_state_1 = require("prosemirror-state");
const commands_1 = require("./commands.js");
const startActionName = 'addEmptyDefaultTextblockToStartOfDocument';
const endActionName = 'addEmptyDefaultTextblockToEndOfDocument';
const ClicksOnEdges = (builder) => {
    builder.addAction(startActionName, () => ({
        isEnable: commands_1.addParagraphToStart,
        run: commands_1.addParagraphToStart,
    }));
    builder.addAction(endActionName, () => ({
        isEnable: commands_1.addParagraphToEnd,
        run: commands_1.addParagraphToEnd,
    }));
    builder.addPlugin(() => {
        return new prosemirror_state_1.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 (0, commands_1.addParagraphToStart)(view.state, view.dispatch);
                    }
                    if (event.offsetY > lastOffsetBottom) {
                        return (0, commands_1.addParagraphToEnd)(view.state, view.dispatch);
                    }
                    return false;
                },
            },
        });
    });
};
exports.ClicksOnEdges = ClicksOnEdges;
//# sourceMappingURL=ClicksOnEdges.js.map
