<commit_before>/**
 * @file Menu component
 * @author liangxiaojun(<EMAIL>)
 */

import React, {Component} from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

import Popover from '../Popover';
import Theme from '../Theme';

import Position from '../_statics/Position';
import Event from '../_vendors/Event';
import Dom from '../_vendors/Dom';
import Util from '../_vendors/Util';

class Menu extends Component {

    static Position = Position;
    static Theme = Theme;

    constructor(props, ...restArgs) {

        super(props, ...restArgs);

        this.closeTimeout = null;

        this.clearCloseTimeout = ::this.clearCloseTimeout;
        this.mouseMoveHandler = ::this.mouseMoveHandler;

    }

    clearCloseTimeout() {
        if (this.closeTimeout) {
            clearTimeout(this.closeTimeout);
            this.closeTimeout = null;
        }
    }

    triggerHandler(el, triggerEl, popupEl, currentVisible, isAutoClose) {

        while (el) {
            if (el == popupEl) {
                return currentVisible;
            }
            el = el.parentNode;
        }

        return isAutoClose ? false : currentVisible;

    }

    mouseMoveHandler(e) {

        const {visible, triggerEl, isAutoClose, triggerHandler, onRequestClose} = this.props,
            popupEl = this.refs.menu.getEl();

        if (!triggerEl) {
            return;
        }

        let currVisible;

        if (triggerHandler) {
            currVisible = triggerHandler(e.target, triggerEl, popupEl, visible, isAutoClose);
        } else if (!Dom.isParent(e.target, triggerEl)) {
            currVisible = this.triggerHandler(e.target, triggerEl, popupEl, visible, isAutoClose);
        }

        this.clearCloseTimeout();

        if (currVisible === false) {
            this.closeTimeout = setTimeout(() => {
                onRequestClose && onRequestClose(e);
            }, 100);
        }

    }

    /**
     * public
     */
    resetPosition() {
        this.refs.menu.resetPosition();
    }

    componentDidMount() {
        Event.addEvent(document, 'mousemove', this.mouseMoveHandler);
    }

    componentWillUnmount() {
        this.clearCloseTimeout();
        Event.removeEvent(document, 'mousemove', this.mouseMoveHandler);
    }

    render() {

        const {

                className,

                // not passing down these props
                triggerHandler, onRequestClose,

                ...restProps

            } = this.props,

            popupClassName = classNames('menu', {
                [className]: className
            });

        return (
            <Popover {...restProps}
                     ref="menu"
                     className={popupClassName}
                     contentClassName="menu-content"/>
        );<commit_msg>update Menu<commit_after>/**
 * @file Menu component
 * @author liangxiaojun(<EMAIL>)
 */

import React, {Component} from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

import Popover from '../Popover';
import Theme from '../Theme';

import Position from '../_statics/Position';
import Event from '../_vendors/Event';
import Dom from '../_vendors/Dom';
import Util from '../_vendors/Util';

class Menu extends Component {

    static Position = Position;
    static Theme = Theme;

    constructor(props, ...restArgs) {

        super(props, ...restArgs);

        this.closeTimeout = null;

        this.clearCloseTimeout = ::this.clearCloseTimeout;
        this.mouseOverHandler = ::this.mouseOverHandler;
        this.mouseOutHandler = ::this.mouseOutHandler;
        this.renderHandler = ::this.renderHandler;
        this.destroyHandler = ::this.destroyHandler;

    }

    clearCloseTimeout() {
        if (this.closeTimeout) {
            clearTimeout(this.closeTimeout);
            this.closeTimeout = null;
        }
    }

    triggerHandler(el, triggerEl, popupEl, currentVisible, isAutoClose) {

        while (el) {
            if (el == popupEl) {
                return currentVisible;
            }
            el = el.parentNode;
        }

        return isAutoClose ? false : currentVisible;

    }

    // mouseOutHandler(e) {
    //
    //     const {visible, triggerEl, isAutoClose, triggerHandler, onRequestClose} = this.props,
    //         popupEl = this.refs.menu.getEl();
    //
    //     if (!triggerEl) {
    //         return;
    //     }
    //
    //     let currVisible;
    //
    //     if (triggerHandler) {
    //         currVisible = triggerHandler(e.target, triggerEl, popupEl, visible, isAutoClose);
    //     } else if (!Dom.isParent(e.target, triggerEl)) {
    //         currVisible = this.triggerHandler(e.target, triggerEl, popupEl, visible, isAutoClose);
    //     }
    //
    //     this.clearCloseTimeout();
    //
    //     if (currVisible === false) {
    //         this.closeTimeout = setTimeout(() => {
    //             onRequestClose && onRequestClose(e);
    //         }, 100);
    //     }
    //
    // }

    mouseOverHandler() {
        this.clearCloseTimeout();
    }

    mouseOutHandler(e) {
        const {onRequestClose} = this.props;
        this.clearCloseTimeout();
        this.closeTimeout = setTimeout(() => {
            onRequestClose && onRequestClose(e);
        }, 1000 / 6);
    }

    renderHandler(el) {
        const {triggerEl} = this.props;
        Event.addEvent(triggerEl, 'mouseover', this.mouseOverHandler);
        Event.addEvent(triggerEl, 'mouseout', this.mouseOutHandler);
        Event.addEvent(el, 'mouseover', this.mouseOverHandler);
        Event.addEvent(el, 'mouseout', this.mouseOutHandler);
    }

    destroyHandler(el) {
        const {triggerEl} = this.props;
        Event.removeEvent(triggerEl, 'mouseover', this.mouseOverHandler);
        Event.removeEvent(triggerEl, 'mouseout', this.mouseOutHandler);
        Event.removeEvent(el, 'mouseover', this.mouseOverHandler);
        Event.removeEvent(el, 'mousemove', this.mouseOutHandler);
    }

    /**
     * public
     */
    resetPosition() {
        this.refs.menu.resetPosition();
    }

    componentDidMount() {
        // Event.addEvent(document, 'mousemove', this.mouseOutHandler);
    }

    componentWillUnmount() {
        this.clearCloseTimeout();
        // Event.removeEvent(document, 'mousemove', this.mouseOutHandler);
    }

    render() {

        const {

                className,

                // not passing down these props
                triggerHandler, onRequestClose,

                ...restProps

            } = this.props,

            popupClassName = classNames('menu', {
                [className]: className
            });

        return (
            <Popover {...restProps}
                     ref="menu"
                     className={popupClassName}
                     contentClassName="menu-content"
                     onRender={this.renderHandler}
                     onDestroy={this.destroyHandler}/>
        );
{'fraction_non_alphanumeric': 0.1240343347639485, 'fraction_numerical': 0.0015736766809728183, 'mean_word_length': 1.904445367677607, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '573079', 'n_tokens_mistral': 1963, 'n_tokens_neox': 1862, 'n_words': 380}