<commit_before>import {Table} from "../elements/Table";
import {Cell} from "./Cell";
import {EventManager} from "../utils/EventManager";
import {UUID} from "../utils/UUID";

// declare const $:JQueryStatic;

export class EditField {

    private inputField: any;
    private lastDisabled: number;
    private static DISABLE_TO_ENABLE_TRANSITION_THRESHOLD: number = 300;

    // Margin around the edited field in which it is safely click without disabling the edit mode
    private static SAFE_TO_EDIT_MARGIN: number = 10; // in px

    constructor(cell: Cell) {
        this.load(cell);
    }

    private load(cell: Cell) {
        this.inputField = $("<input>").addClass(Table.CLASSES.input).val(cell.element.text());
    }

    public get() {
        return this.inputField.val();
    }

    public remove() {
        this.inputField.remove();
    }

    public edit(cell: Cell, event: BaseJQueryEventObject) {

        if (cell.readOnly) {
            return;
        }

        if (cell.editMode) {
            return;
        }
        else {
            this.enable(cell, event);

        }
    }

    public disable(event) {
        const cell: Cell = event.data.cell;
        const self: EditField = event.data.self;
        if (self.inBounds(event)) {
            // Clicking on the same cell has to be ignored
            return true;
        }
        let text: string = self.inputField.val();
        cell.element.empty();
        cell.element.text(text);
        cell.editMode = false;
        const container = cell.table.container;
        if (container) {
            container.off("mousedown." + cell.element.attr("id"));<commit_msg>Improve state encapsulation in EditField<commit_after>import {Table} from "../elements/Table";
import {Cell} from "./Cell";
import {EventManager} from "../utils/EventManager";
import {UUID} from "../utils/UUID";

// declare const $:JQueryStatic;

export class EditField {

    private inputField: any;
    private lastDisabled: number;
    private static DISABLE_TO_ENABLE_TRANSITION_THRESHOLD: number = 300;

    // Margin around the edited field in which it is safely click without disabling the edit mode
    private static SAFE_TO_EDIT_MARGIN: number = 10; // in px

    constructor(cell: Cell) {
        this.load(cell);
    }

    private load(cell: Cell) {
        this.inputField = $("<input>").addClass(Table.CLASSES.input).val(cell.element.text());
    }

    public get() {
        return this.inputField.val();
    }

    public remove() {
        this.inputField.remove();
    }

    public edit(cell: Cell, event: BaseJQueryEventObject) {

        if (cell.readOnly) {
            return;
        }

        if (cell.editMode) {
            return;
        }
        else {
            this.enable(cell, event);

        }
    }

    public disable(event) {
        const cell: Cell = event.data.cell;
        const self: EditField = event.data.self;
        if (self.inBounds(event)) {
            // Clicking on the same cell has to be ignored
            return true;
        }
        let text: string = self.inputField.val();
        cell.element.empty();
        cell.element.text(text);
        cell.content = text;
        cell.editMode = false;
        const container = cell.table.container;
        if (container) {
            container.off("mousedown." + cell.element.attr("id"));
{'fraction_non_alphanumeric': 0.12060750446694461, 'fraction_numerical': 0.0029779630732578916, 'mean_word_length': 2.1778618732261115, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2852245', 'n_tokens_mistral': 992, 'n_tokens_neox': 959, 'n_words': 251}