import { useLayoutEffect, useMemo, useState } from 'react';
import { useLatest } from 'react-use';
export function useSharedEditingState(view, key) {
    const [value, setValue] = useState(false);
    const valueRef = useLatest(value);
    useLayoutEffect(() => {
        setValue(key.getValue(view.state)?.editing || false);
        return key.getNotifier(view.state).subscribe((data) => setValue(data?.editing || false));
    }, [key, view]);
    const { set, unset, toggle } = useMemo(() => {
        const dispatch = (value) => {
            view.dispatch(key.appendTransaction.update(view.state.tr, { editing: value }));
        };
        return {
            set: () => dispatch(true),
            unset: () => dispatch(false),
            toggle: () => dispatch(!valueRef.current),
        };
    }, [key, view, valueRef]);
    return [value, set, unset, toggle];
}
//# sourceMappingURL=useSharedEditingState.js.map
