How to use the babylonjs-editor.CodeEditor function in babylonjs-editor

To help you get started, we’ve selected a few babylonjs-editor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github BabylonJS / Editor / src / code-project-editor / code-editor.ts View on Github external
// Create tab
        this.codeEditor.codeLayout.layout.addPanelToStack('edit-panel', {
            type: 'component',
            title: code.name,
            componentName: code.id,
            html: `<div style="width: 100%; height: 100%;" id="${code.id}-editor"></div>`,
            onClose: () =&gt; {
                this.code.dispose();
                
                if (this.onClose)
                    this.onClose();
            }
        });

        // Create editor
        this.code = new CodeEditor('typescript', code.code);
        await this.code.build(code.id + '-editor');

        // On the user changes the code
        let compileTimeoutId = -1;

        this.code.onChange = value =&gt; {
            // Set a timeout before transpilation until the user
            // finished typings his code
            clearTimeout(compileTimeoutId);

            compileTimeoutId = setTimeout(() =&gt; {
                const config = {
                    module: 'cjs',
                    target: 'es5',
                    experimentalDecorators: true,
                };
github BabylonJS / Editor / src / tools / metadata / editor.ts View on Github external
public async create(): Promise {
        // Layout
        this.layout = new Layout(this.divElement.id);
        this.layout.panels = [
            { type: 'top', size: 30, resizable: false, content: '<div style="width: 100%; height: 100%;" id="METADATA-EDITOR-TOOLBAR"></div>' },
            { type: 'main', content: '<div style="width: 100%; height: 100%;" id="METADATA-EDITOR-EDITOR"></div>' }
        ]
        this.layout.build(this.divElement.id);

        // Toolbar
        this.toolbar = new Toolbar('METADATA-EDITOR-TOOLBAR');
        this.toolbar.build('METADATA-EDITOR-TOOLBAR');

        // Create json editor
        this.code = new CodeEditor('json', '{\n\n}');
        this.code.onChange = (value) =&gt; {
            if (!this.selectedNode)
                return;

            // Clear JSON checker timeout
            if (this._checkTimeout !== -1) {
                clearTimeout(this._checkTimeout);
                this._checkTimeout = -1;
            }
            
            try {
                // Parse JSON text value
                const data = JSON.parse(value);
                this.selectedNode['metadata'].customMetadatas = data;
                this.toolbar.notifyMessage('');
            } catch (e) {
github BabylonJS / Editor / src / tools / behavior / code.ts View on Github external
protected async createEditor (): Promise {
        this.code = new CodeEditor('javascript');
        await this.code.build('CODE-BEHAVIOR-EDITOR');

        this.code.onChange = value =&gt; {
            if (this.data)
                this.data.code = this.code.getValue();
        };
    }
}