"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useCaret = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const hooks_1 = require("../hooks");
const useCaret = () => {
    const ref = React.useRef(null);
    const timer = React.useRef();
    (0, hooks_1.useBrowserLayoutEffect)(() => {
        const span = ref.current;
        if (!span)
            return;
        clearTimeout(timer.current);
        timer.current = setTimeout(() => {
            const selection = window.getSelection();
            if (!selection)
                return;
            const range = document.createRange();
            range.setStart(span, 0);
            range.collapse(true);
            selection.removeAllRanges();
            selection.addRange(range);
        }, 1);
        return () => {
            clearTimeout(timer.current);
        };
    });
    return ref;
};
exports.useCaret = useCaret;
//# sourceMappingURL=hooks.js.map