Sha256: 9cebe159dcde9debe1d849aa2c3b8ae7bac8a5c3ef6e03480f3baea2967cbe3e

Contents?: true

Size: 1.6 KB

Versions: 39

Compression:

Stored size: 1.6 KB

Contents

import 'codemirror/mode/css/css'
import 'codemirror/mode/dockerfile/dockerfile'
import 'codemirror/mode/htmlmixed/htmlmixed'
import 'codemirror/mode/javascript/javascript'
import 'codemirror/mode/markdown/markdown'
import 'codemirror/mode/nginx/nginx'
import 'codemirror/mode/php/php'
import 'codemirror/mode/ruby/ruby'
import 'codemirror/mode/sass/sass'
import 'codemirror/mode/shell/shell'
import 'codemirror/mode/sql/sql'
import 'codemirror/mode/vue/vue'
import 'codemirror/mode/xml/xml'
import 'codemirror/mode/yaml/yaml'

import { Controller } from '@hotwired/stimulus'
import CodeMirror from 'codemirror'

import { castBoolean } from '../../helpers/cast_boolean'

export default class extends Controller {
  static targets = ['element']

  connect() {
    const options = {
      readOnly: castBoolean(this.elementTarget.dataset.readOnly),
      mode: this.elementTarget.dataset.language,
      theme: this.elementTarget.dataset.theme,
      tabSize: this.elementTarget.dataset.tabSize,
      indentWithTabs: castBoolean(this.elementTarget.dataset.indentWithTabs),
      lineWrapping: castBoolean(this.elementTarget.dataset.lineWrapping),
      lineNumbers: true,
    }

    const vm = this

    setTimeout(() => {
      CodeMirror.fromTextArea(this.elementTarget, options).on('change', (cm) => {
        // Add this innerText change and dispatch an event to allow stimulus to pick up the input event.
        vm.elementTarget.innerText = cm.getValue()
        vm.elementTarget.dispatchEvent(new Event('input'))
      })
    }, 1)
  }

  disconnect() {
    this.element.querySelector('.CodeMirror').CodeMirror.toTextArea()
  }
}

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
avo-3.15.1 app/javascript/js/controllers/fields/code_field_controller.js
avo-3.15.0 app/javascript/js/controllers/fields/code_field_controller.js
avo-3.14.5 app/javascript/js/controllers/fields/code_field_controller.js
avo-3.14.4 app/javascript/js/controllers/fields/code_field_controller.js
avo-3.14.3 app/javascript/js/controllers/fields/code_field_controller.js
avo-3.14.2 app/javascript/js/controllers/fields/code_field_controller.js
avo-3.14.1 app/javascript/js/controllers/fields/code_field_controller.js
avo-3.14.0 app/javascript/js/controllers/fields/code_field_controller.js
avo-3.13.7 app/javascript/js/controllers/fields/code_field_controller.js
avo-3.13.6 app/javascript/js/controllers/fields/code_field_controller.js
avo-3.13.5 app/javascript/js/controllers/fields/code_field_controller.js
avo-3.13.4 app/javascript/js/controllers/fields/code_field_controller.js
avo-3.13.3 app/javascript/js/controllers/fields/code_field_controller.js
avo-3.13.2 app/javascript/js/controllers/fields/code_field_controller.js
avo-3.13.1 app/javascript/js/controllers/fields/code_field_controller.js
avo-3.13.0 app/javascript/js/controllers/fields/code_field_controller.js
avo-3.12.0 app/javascript/js/controllers/fields/code_field_controller.js
avo-3.11.10 app/javascript/js/controllers/fields/code_field_controller.js
avo-3.11.9 app/javascript/js/controllers/fields/code_field_controller.js
avo-3.11.8 app/javascript/js/controllers/fields/code_field_controller.js