<commit_before>import * as React from "react";
import * as ReactDOM from "react-dom";
import { GlobalState } from "./globalState";
import { WorkbenchEditor } from "./workbenchEditor";
import { Popup } from "./sharedUiComponents/lines/popup";
import { Observable } from "babylonjs/Misc/observable";
import { AdvancedDynamicTexture } from "babylonjs-gui/2D/advancedDynamicTexture";

/**
 * Interface used to specify creation options for the gui editor
 */
export interface IGUIEditorOptions {
    liveGuiTexture?: AdvancedDynamicTexture;
    customLoad: { label: string; action: (data: string) => Promise<string>; } | undefined;
    hostElement?: HTMLElement;
    customSave?: { label: string; action: (data: string) => Promise<string> };
    currentSnippetToken?: string;
    customLoadObservable?: Observable<any>;
}

/**
 * Class used to create a gui editor
 */
export class GUIEditor {
    private static _CurrentState: GlobalState;
    /**
     * Show the gui editor
     * @param options defines the options to use to configure the gui editor
     */
    public static async Show(options: IGUIEditorOptions) {
        let hostElement = options.hostElement;

        // if we are in a standalone window and we have some current state, just load the GUI from the snippet server, don't do anything else
        if (this._CurrentState && hostElement) {
            if (options.currentSnippetToken) {
                try {
                    this._CurrentState.workbench.loadFromSnippet(options.currentSnippetToken);
                } catch (error) {
                    //swallow and continue
                }
            }
            return;
        }

        if (!hostElement) {
            var popupWindow = (Popup as any)["gui-editor"];
            if (popupWindow) {
                popupWindow.close();
            }
            hostElement = Popup.CreatePopup("BABYLON.JS GUI EDITOR", "gui-editor", 1200, 800)!;
        }

        let globalState = new GlobalState();
        if (options.liveGuiTexture) {
            globalState.liveGuiTexture = options.liveGuiTexture;
        }
        globalState.hostElement = hostElement;
        globalState.hostDocument = hostElement.ownerDocument!;
        globalState.customSave = options.customSave;
        globalState.customLoad = options.customLoad;
        globalState.hostWindow = hostElement.ownerDocument!.defaultView!;

        const graphEditor = React.createElement(WorkbenchEditor, {
            globalState: globalState,
        });

        ReactDOM.render(graphEditor, hostElement);
        // create the middle workbench canvas
        if (!globalState.guiTexture) {
            globalState.workbench.createGUICanvas();
            globalState.guiGizmo.createBaseGizmo();
            if (options.currentSnippetToken) {
                try {
                    await globalState.workbench.loadFromSnippet(options.currentSnippetToken);

                } catch (error) {
                    //swallow and continue
                }
            }
        }

        if (options.customLoadObservable) {
            options.customLoadObservable.add((data) => {
                globalState.onResetRequiredObservable.notifyObservers();
                globalState.onBuiltObservable.notifyObservers();
            });
        }

        this._CurrentState = globalState;

        // Close the popup window when the page is refreshed or scene is disposed
        var popupWindow = (Popup as any)["gui-editor"];
        if (popupWindow) {
            window.onbeforeunload = () => {
                var popupWindow = (Popup as any)["gui-editor"];
                if (popupWindow) {
                    popupWindow.close();
                }
            };
        }
        globalState.hostWindow.addEventListener("beforeunload", () => {
            globalState.onPopupClosedObservable.notifyObservers();
        });
    }
}<commit_msg>remove createBaseGizmo call (no longer needed)<commit_after>import * as React from "react";
import * as ReactDOM from "react-dom";
import { GlobalState } from "./globalState";
import { WorkbenchEditor } from "./workbenchEditor";
import { Popup } from "./sharedUiComponents/lines/popup";
import { Observable } from "babylonjs/Misc/observable";
import { AdvancedDynamicTexture } from "babylonjs-gui/2D/advancedDynamicTexture";

/**
 * Interface used to specify creation options for the gui editor
 */
export interface IGUIEditorOptions {
    liveGuiTexture?: AdvancedDynamicTexture;
    customLoad: { label: string; action: (data: string) => Promise<string>; } | undefined;
    hostElement?: HTMLElement;
    customSave?: { label: string; action: (data: string) => Promise<string> };
    currentSnippetToken?: string;
    customLoadObservable?: Observable<any>;
}

/**
 * Class used to create a gui editor
 */
export class GUIEditor {
    private static _CurrentState: GlobalState;
    /**
     * Show the gui editor
     * @param options defines the options to use to configure the gui editor
     */
    public static async Show(options: IGUIEditorOptions) {
        let hostElement = options.hostElement;

        // if we are in a standalone window and we have some current state, just load the GUI from the snippet server, don't do anything else
        if (this._CurrentState && hostElement) {
            if (options.currentSnippetToken) {
                try {
                    this._CurrentState.workbench.loadFromSnippet(options.currentSnippetToken);
                } catch (error) {
                    //swallow and continue
                }
            }
            return;
        }

        if (!hostElement) {
            var popupWindow = (Popup as any)["gui-editor"];
            if (popupWindow) {
                popupWindow.close();
            }
            hostElement = Popup.CreatePopup("BABYLON.JS GUI EDITOR", "gui-editor", 1200, 800)!;
        }

        let globalState = new GlobalState();
        if (options.liveGuiTexture) {
            globalState.liveGuiTexture = options.liveGuiTexture;
        }
        globalState.hostElement = hostElement;
        globalState.hostDocument = hostElement.ownerDocument!;
        globalState.customSave = options.customSave;
        globalState.customLoad = options.customLoad;
        globalState.hostWindow = hostElement.ownerDocument!.defaultView!;

        const graphEditor = React.createElement(WorkbenchEditor, {
            globalState: globalState,
        });

        ReactDOM.render(graphEditor, hostElement);
        // create the middle workbench canvas
        if (!globalState.guiTexture) {
            globalState.workbench.createGUICanvas();
            if (options.currentSnippetToken) {
                try {
                    await globalState.workbench.loadFromSnippet(options.currentSnippetToken);

                } catch (error) {
                    //swallow and continue
                }
            }
        }

        if (options.customLoadObservable) {
            options.customLoadObservable.add((data) => {
                globalState.onResetRequiredObservable.notifyObservers();
                globalState.onBuiltObservable.notifyObservers();
            });
        }

        this._CurrentState = globalState;

        // Close the popup window when the page is refreshed or scene is disposed
        var popupWindow = (Popup as any)["gui-editor"];
        if (popupWindow) {
            window.onbeforeunload = () => {
                var popupWindow = (Popup as any)["gui-editor"];
                if (popupWindow) {
                    popupWindow.close();
                }
            };
        }
        globalState.hostWindow.addEventListener("beforeunload", () => {
            globalState.onPopupClosedObservable.notifyObservers();
        });
    }
}
{'fraction_non_alphanumeric': 0.09383613129541468, 'fraction_numerical': 0.0020045101478326235, 'mean_word_length': 2.010180995475113, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, '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': '5971510', 'n_tokens_mistral': 2076, 'n_tokens_neox': 1959, 'n_words': 486}