<commit_before>import { HTMLAssembler, NodeInit } from './htmlmodule';

import CodeMirror from 'codemirror';
import 'codemirror/mode/javascript/javascript';
import 'codemirror/mode/htmlmixed/htmlmixed';

import 'codemirror/lib/codemirror.css';
import './codemirror.css';

import 'codemirror/theme/rubyblue.css';
const theme = 'rubyblue';

const CODE_BOX_DEFAULTS = {
    mode : 'javascript',
    indentUnit : 4,
    tabSize : 4,
    indentWithTabs : true,
    electricChars : true,
    styleActiveLine : true,
    autoCloseBrackets : true,
    matchBrackets : true,
    smartIndent : true,
    theme
};

const MARKUP_BOX_DEFAULTS = {
    mode : 'htmlmixed',
    readOnly : true,
    theme
};

export class CodeMirrorAssembler extends HTMLAssembler {
    constructor(init) {
        super(init);
        this.createElement('div', NodeInit(init));
    }
    set value(value) {
        this.mirror.setValue(value && value.toString());
    }
    get value() {
        return this.mirror.getValue();
    }
    get height() {
        return this.element.clientHeight;
    }
    set onchange(onchange) {
        this.mirror.on('change', onchange);
    }
    set id(id) {
        this.element.querySelector('textarea').id = id;
    }
    createElement(tagName, init) {
        super.createElement(tagName);
        this.createMirror(init.options);
        delete init.options;
        this.init(init);
    }
    createMirror(options) {
        return this.mirror = new CodeMirror(this.element, options);
    }
    refresh() {
        this.mirror.refresh();
    }
}

Object.defineProperty(CodeMirrorAssembler.prototype, 'mirror', { writable : true, value : null });

/**
 * Create generic codemirror widget
 * @param init
 * @returns {CodeMirrorAssembler}
 */
export function codemirror(init = {}) {
    return new CodeMirrorAssembler(init);
}

/**
 * Create codebox widget
 * @param init
 * @returns {CodeMirrorAssembler}
 */
export function codebox(init = {}) {
    if(!init.options) init.options = CODE_BOX_DEFAULTS;
    return codemirror(init);
}<commit_msg>jsdoc<commit_after>import { HTMLAssembler, NodeInit } from './htmlmodule';

import CodeMirror from 'codemirror';
import 'codemirror/mode/javascript/javascript';
import 'codemirror/mode/htmlmixed/htmlmixed';

import 'codemirror/lib/codemirror.css';
import './codemirror.css';

import 'codemirror/theme/rubyblue.css';
const theme = 'rubyblue';

const CODE_BOX_DEFAULTS = {
    mode : 'javascript',
    indentUnit : 4,
    tabSize : 4,
    indentWithTabs : true,
    electricChars : true,
    styleActiveLine : true,
    autoCloseBrackets : true,
    matchBrackets : true,
    smartIndent : true,
    theme
};

const MARKUP_BOX_DEFAULTS = {
    mode : 'htmlmixed',
    readOnly : true,
    theme
};

export class CodeMirrorAssembler extends HTMLAssembler {
    constructor(init) {
        super(init);
        this.createElement('div', NodeInit(init));
    }
    set value(value) {
        this.mirror.setValue(value && value.toString());
    }
    get value() {
        return this.mirror.getValue();
    }
    get height() {
        return this.element.clientHeight;
    }
    set onchange(onchange) {
        this.mirror.on('change', onchange);
    }
    set id(id) {
        this.element.querySelector('textarea').id = id;
    }
    createElement(tagName, init) {
        super.createElement(tagName);
        this.createMirror(init.options);
        delete init.options;
        this.init(init);
    }
    createMirror(options) {
        return this.mirror = new CodeMirror(this.element, options);
    }
    refresh() {
        this.mirror.refresh();
    }
}

/**
 * CodeMirror instance
 * @property mirror
 * @type {CodeMirror|null}
 */
CodeMirrorAssembler.prototype.mirror = null;

/**
 * Create generic codemirror widget
 * @param init
 * @returns {CodeMirrorAssembler}
 */
export function codemirror(init = {}) {
    return new CodeMirrorAssembler(init);
}

/**
 * Create codebox widget
 * @param init
 * @returns {CodeMirrorAssembler}
 */
export function codebox(init = {}) {
    if(!init.options) init.options = CODE_BOX_DEFAULTS;
    return codemirror(init);
}
{'fraction_non_alphanumeric': 0.12688015526443475, 'fraction_numerical': 0.0009704027171276079, 'mean_word_length': 3.0943396226415096, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4588331', 'n_tokens_mistral': 1350, 'n_tokens_neox': 1312, 'n_words': 260}