<commit_before>// This is a port of a jQuery library:
// https://github.com/kamens/jQuery-menu-aim

import * as React from "react"
import { bind } from "decko"

interface Position {
    x: number
    y: number
}

const ATTRIBUTE = "data-submenu-id"
const MOUSE_LOCS_TRACKED = 3
const DELAY = 400
const TOLERANCE_PX = 20

const getParent = (
    el: HTMLElement,
    condition: (el: HTMLElement) => boolean
): HTMLElement | null => {
    let current: HTMLElement | null = el
    while (current) {
        if (condition(current)) return current
        current = current.parentElement
    }
    return null
}

const getSubmenuId = (targetEl: HTMLElement): string | null => {
    const listItem = getParent(targetEl, (el: HTMLElement) =>
        el.matches(`[${ATTRIBUTE}]`)
    )
    return listItem ? listItem.getAttribute(ATTRIBUTE) : null
}

const slope = (a: Position, b: Position) => (b.y - a.y) / (b.x - a.x)

export class AmazonMenu extends React.Component<{
    children: React.ReactNode
    submenuRect?: DOMRect | ClientRect | null
    onActivate?: (submenuId: any) => void
    onDeactivate?: (submenuId: any) => void
}> {
    container: React.RefObject<HTMLDivElement> = React.createRef()
    activeSubmenuId?: string
    mouseLocs: Position[] = []
    lastDelayLoc?: Position
    timeoutId?: number

    @bind onMouseMove(event: React.MouseEvent<HTMLDivElement>) {<commit_msg>refactor(menu): use getDOMParent from Utils<commit_after>// This is a port of a jQuery library:
// https://github.com/kamens/jQuery-menu-aim

import * as React from "react"
import { bind } from "decko"
import { getDOMParent } from "../clientUtils/Util"

interface Position {
    x: number
    y: number
}

const ATTRIBUTE = "data-submenu-id"
const MOUSE_LOCS_TRACKED = 3
const DELAY = 400
const TOLERANCE_PX = 20

const getSubmenuId = (targetEl: HTMLElement): string | null => {
    const listItem = getDOMParent(targetEl, (el: HTMLElement) =>
        el.matches(`[${ATTRIBUTE}]`)
    )
    return listItem ? listItem.getAttribute(ATTRIBUTE) : null
}

const slope = (a: Position, b: Position) => (b.y - a.y) / (b.x - a.x)

export class AmazonMenu extends React.Component<{
    children: React.ReactNode
    submenuRect?: DOMRect | ClientRect | null
    onActivate?: (submenuId: any) => void
    onDeactivate?: (submenuId: any) => void
}> {
    container: React.RefObject<HTMLDivElement> = React.createRef()
    activeSubmenuId?: string
    mouseLocs: Position[] = []
    lastDelayLoc?: Position
    timeoutId?: number

    @bind onMouseMove(event: React.MouseEvent<HTMLDivElement>) {
{'fraction_non_alphanumeric': 0.126508369015181, 'fraction_numerical': 0.004671078240560529, 'mean_word_length': 3.597495527728086, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 21, 'https://': 2, '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': '1313963', 'n_tokens_mistral': 853, 'n_tokens_neox': 851, 'n_words': 225}