"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useNodeEditing = void 0;
const react_1 = require("react");
const hooks_1 = require("./hooks.js");
const useNodeEditing = ({ nodeRef, view }) => {
    const state = (0, hooks_1.useBooleanState)(false);
    const [, , unsetEdit, toggleEdit] = state;
    (0, react_1.useEffect)(() => {
        const { current: anchor } = nodeRef;
        anchor?.addEventListener('dblclick', toggleEdit);
        view.dom.addEventListener('focus', unsetEdit);
        return () => {
            anchor?.removeEventListener('dblclick', toggleEdit);
            view.dom.removeEventListener('focus', unsetEdit);
        };
        // https://github.com/facebook/react/issues/23392#issuecomment-1055610198
        // eslint-disable-next-line react-hooks/exhaustive-deps
    }, [view.dom, toggleEdit, unsetEdit, nodeRef.current]);
    return state;
};
exports.useNodeEditing = useNodeEditing;
//# sourceMappingURL=useNodeEditing.js.map
