<commit_before>import * as React from "react";
import Rect from "./Rect";

/** @hidden @internal */
const canUseDOM = !!(typeof window !== "undefined" && window.document && window.document.createElement);

class DragDrop {
    static instance = new DragDrop();

    /** @hidden @internal */
    private _fDblClick: ((event: Event) => void) | undefined;
    /** @hidden @internal */
    private _fClick: ((event: Event) => void) | undefined;
    /** @hidden @internal */
    private _fDragEnd: ((event: Event) => void) | undefined;
    /** @hidden @internal */
    private _fDragMove: ((event: React.MouseEvent<Element>) => void) | undefined;
    /** @hidden @internal */
    private _fDragStart: ((pos: { clientX: number; clientY: number }) => boolean) | undefined;
    /** @hidden @internal */
    private _fDragCancel: ((wasDragging: boolean) => void) | undefined;

    /** @hidden @internal */
    private _glass: HTMLDivElement | undefined;
    /** @hidden @internal */
    private _defaultGlassCursor: string;
    /** @hidden @internal */
    private _glassCursorOverride: string | undefined;
    /** @hidden @internal */
    private _manualGlassManagement: boolean = false;
    /** @hidden @internal */
    private _lastClick: number;
    /** @hidden @internal */
    private _clickX: number;
    /** @hidden @internal */
    private _clickY: number;
    /** @hidden @internal */
    private _startX: number = 0;
    /** @hidden @internal */
    private _startY: number = 0;
    /** @hidden @internal */
    private _dragDepth: number = 0;
    /** @hidden @internal */
    private _glassShowing: boolean = false;
    /** @hidden @internal */
    private _dragging: boolean = false;
    /** @hidden @internal */
    private _active: boolean = false; // drag and drop is in progress, can be used on ios to prevent body scrolling (see demo)
    /** @hidden @internal */
    private _document?: HTMLDocument;
    /** @hidden @internal */
    private _rootElement?: HTMLElement | undefined;
    /** @hidden @internal */
    private _lastEvent?: Event | React.MouseEvent<HTMLDivElement, MouseEvent> | React.TouchEvent<HTMLDivElement> | React.DragEvent<Element> | undefined;

    /** @hidden @internal */
    private constructor() {
        if (canUseDOM) {
            // check for serverside rendering
            this._glass = document.createElement("div");
            this._glass.style.zIndex = "998";
            this._glass.style.backgroundColor = "transparent";
            this._glass.style.outline = "none";
        }

        this._defaultGlassCursor = "default";

        this._onMouseMove = this._onMouseMove.bind(this);
        this._onMouseUp = this._onMouseUp.bind(this);
        this._onKeyPress = this._onKeyPress.bind(this);
        this._onDragCancel = this._onDragCancel.bind(this);
        this._onDragEnter = this._onDragEnter.bind(this);
        this._onDragLeave = this._onDragLeave.bind(this);
        this.resizeGlass = this.resizeGlass.bind(this);

        this._lastClick = 0;
        this._clickX = 0;
        this._clickY = 0;
    }

    // if you add the glass pane then you should remove it
    addGlass(fCancel: ((wasDragging: boolean) => void) | undefined) {
        if (!this._glassShowing) {
            if (!this._document) {
                this._document = window.document;
            }
            if (!this._rootElement) {
                this._rootElement = this._document.body;
            }
            this.resizeGlass();
            this._document.defaultView?.addEventListener('resize', this.resizeGlass);
            this._document.body.appendChild(this._glass!);
            this._glass!.tabIndex = -1;
            this._glass!.focus();
            this._glass!.addEventListener("keydown", this._onKeyPress);
            this._glass!.addEventListener("dragenter", this._onDragEnter, { passive: false });
            this._glass!.addEventListener("dragover", this._onMouseMove, { passive: false });
            this._glass!.addEventListener("dragleave", this._onDragLeave, { passive: false });
            this._glassShowing = true;
            this._fDragCancel = fCancel;
            this._manualGlassManagement = false;
        } else {
            // second call to addGlass (via dragstart)
            this._manualGlassManagement = true;
        }
    }

    resizeGlass() {
        const glassRect = Rect.fromElement(this._rootElement!);
        glassRect.positionElement(this._glass!, "fixed");
    }

    hideGlass() {
        if (this._glassShowing) {
            this._document!.body.removeChild(this._glass!);
            this._document!.defaultView?.removeEventListener('resize', this.resizeGlass);
            this._glassShowing = false;
            this._document = undefined;
            this._rootElement = undefined;
        }
    }

    /** @hidden @internal */
    _updateGlassCursor() {
        this._glass!.style.cursor = this._glassCursorOverride ?? this._defaultGlassCursor;
    }

    /** @hidden @internal */
    _setDefaultGlassCursor(cursor: string) {
        this._defaultGlassCursor = cursor;
        this._updateGlassCursor()
    }

    setGlassCursorOverride(cursor: string | undefined) {
        this._glassCursorOverride = cursor;
        this._updateGlassCursor()<commit_msg>fix cursor not being reset after drag<commit_after>import * as React from "react";
import Rect from "./Rect";

/** @hidden @internal */
const canUseDOM = !!(typeof window !== "undefined" && window.document && window.document.createElement);

class DragDrop {
    static instance = new DragDrop();

    /** @hidden @internal */
    private _fDblClick: ((event: Event) => void) | undefined;
    /** @hidden @internal */
    private _fClick: ((event: Event) => void) | undefined;
    /** @hidden @internal */
    private _fDragEnd: ((event: Event) => void) | undefined;
    /** @hidden @internal */
    private _fDragMove: ((event: React.MouseEvent<Element>) => void) | undefined;
    /** @hidden @internal */
    private _fDragStart: ((pos: { clientX: number; clientY: number }) => boolean) | undefined;
    /** @hidden @internal */
    private _fDragCancel: ((wasDragging: boolean) => void) | undefined;

    /** @hidden @internal */
    private _glass: HTMLDivElement | undefined;
    /** @hidden @internal */
    private _defaultGlassCursor: string;
    /** @hidden @internal */
    private _glassCursorOverride: string | undefined;
    /** @hidden @internal */
    private _manualGlassManagement: boolean = false;
    /** @hidden @internal */
    private _lastClick: number;
    /** @hidden @internal */
    private _clickX: number;
    /** @hidden @internal */
    private _clickY: number;
    /** @hidden @internal */
    private _startX: number = 0;
    /** @hidden @internal */
    private _startY: number = 0;
    /** @hidden @internal */
    private _dragDepth: number = 0;
    /** @hidden @internal */
    private _glassShowing: boolean = false;
    /** @hidden @internal */
    private _dragging: boolean = false;
    /** @hidden @internal */
    private _active: boolean = false; // drag and drop is in progress, can be used on ios to prevent body scrolling (see demo)
    /** @hidden @internal */
    private _document?: HTMLDocument;
    /** @hidden @internal */
    private _rootElement?: HTMLElement | undefined;
    /** @hidden @internal */
    private _lastEvent?: Event | React.MouseEvent<HTMLDivElement, MouseEvent> | React.TouchEvent<HTMLDivElement> | React.DragEvent<Element> | undefined;

    /** @hidden @internal */
    private constructor() {
        if (canUseDOM) {
            // check for serverside rendering
            this._glass = document.createElement("div");
            this._glass.style.zIndex = "998";
            this._glass.style.backgroundColor = "transparent";
            this._glass.style.outline = "none";
        }

        this._defaultGlassCursor = "default";

        this._onMouseMove = this._onMouseMove.bind(this);
        this._onMouseUp = this._onMouseUp.bind(this);
        this._onKeyPress = this._onKeyPress.bind(this);
        this._onDragCancel = this._onDragCancel.bind(this);
        this._onDragEnter = this._onDragEnter.bind(this);
        this._onDragLeave = this._onDragLeave.bind(this);
        this.resizeGlass = this.resizeGlass.bind(this);

        this._lastClick = 0;
        this._clickX = 0;
        this._clickY = 0;
    }

    // if you add the glass pane then you should remove it
    addGlass(fCancel: ((wasDragging: boolean) => void) | undefined) {
        if (!this._glassShowing) {
            if (!this._document) {
                this._document = window.document;
            }
            if (!this._rootElement) {
                this._rootElement = this._document.body;
            }
            this.resizeGlass();
            this._document.defaultView?.addEventListener('resize', this.resizeGlass);
            this._document.body.appendChild(this._glass!);
            this._glass!.tabIndex = -1;
            this._glass!.focus();
            this._glass!.addEventListener("keydown", this._onKeyPress);
            this._glass!.addEventListener("dragenter", this._onDragEnter, { passive: false });
            this._glass!.addEventListener("dragover", this._onMouseMove, { passive: false });
            this._glass!.addEventListener("dragleave", this._onDragLeave, { passive: false });
            this._glassShowing = true;
            this._fDragCancel = fCancel;
            this._manualGlassManagement = false;
        } else {
            // second call to addGlass (via dragstart)
            this._manualGlassManagement = true;
        }
    }

    resizeGlass() {
        const glassRect = Rect.fromElement(this._rootElement!);
        glassRect.positionElement(this._glass!, "fixed");
    }

    hideGlass() {
        if (this._glassShowing) {
            this._document!.body.removeChild(this._glass!);
            this._document!.defaultView?.removeEventListener('resize', this.resizeGlass);
            this._glassShowing = false;
            this._document = undefined;
            this._rootElement = undefined;
            this._glassCursorOverride = undefined;
        }
    }

    /** @hidden @internal */
    _updateGlassCursor() {
        this._glass!.style.cursor = this._glassCursorOverride ?? this._defaultGlassCursor;
    }

    /** @hidden @internal */
    _setDefaultGlassCursor(cursor: string) {
        this._defaultGlassCursor = cursor;
        this._updateGlassCursor()
    }

    setGlassCursorOverride(cursor: string | undefined) {
        this._glassCursorOverride = cursor;
        this._updateGlassCursor()
{'fraction_non_alphanumeric': 0.13114908884902277, 'fraction_numerical': 0.0018883958077613068, 'mean_word_length': 2.5555555555555554, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 25, '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': '4505055', 'n_tokens_mistral': 2937, 'n_tokens_neox': 2862, 'n_words': 659}