Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

87 lines
2.6KB

  1. <template>
  2. <div>
  3. <div class="container" :id="name" :style="{'height': `calc(${height} - ( 8rem) )`}"></div>
  4. <div class="tags has-addons">
  5. <span class="tag"><label class="checkbox">
  6. <input type="checkbox" v-model="vim_mode">VIM</label>
  7. </span>
  8. <span class="tag is-primary" :id="`${name}_status`"></span>
  9. </div>
  10. </div>
  11. </template>
  12. <script>
  13. import { initVimMode } from 'monaco-vim';
  14. export default {
  15. props: {
  16. vim_mode: {
  17. type: Boolean,
  18. required: true
  19. },
  20. name: {
  21. type: String,
  22. required: true
  23. },
  24. value: {
  25. type: String,
  26. required: false
  27. },
  28. language: {
  29. type: String,
  30. required: false
  31. },
  32. height: {
  33. type: String,
  34. required: true
  35. }
  36. },
  37. mounted() {
  38. this.editor = monaco.editor.create(document.getElementById(this.name), {
  39. value: this.value,
  40. language: this.language,
  41. automaticLayout: true,
  42. });
  43. /*
  44. fetch('/themes/Dawn.json')
  45. .then(data => data.json())
  46. .then(data => {
  47. monaco.editor.defineTheme('custom', data);
  48. monaco.editor.setTheme('custom');
  49. });
  50. */
  51. this.editor.onDidChangeModelContent(event => {
  52. const value = this.editor.getValue()
  53. if (this.value !== value) {
  54. this.$emit('input', value, event)
  55. }
  56. });
  57. this.vimMode_1 = initVimMode(this.editor, document.getElementById(this.name + "_status"))
  58. },
  59. watch: {
  60. value(new_val) {
  61. if (this.editor) {
  62. if (new_val !== this.editor.getValue()) {
  63. this.editor.setValue(new_val)
  64. this.$emit('input', new_val);
  65. }
  66. }
  67. },
  68. vim_mode(new_val) {
  69. if (new_val) {
  70. this.vimMode_1 = initVimMode(this.editor, document.getElementById(this.name + "_status"))
  71. } else {
  72. this.vimMode_1.dispose();
  73. document.getElementById(this.name + "_status").innerHTML = '';
  74. }
  75. }
  76. }
  77. }
  78. </script>
  79. <style scoped>
  80. .container {
  81. width: calc(50vw - ( 2.5rem) );
  82. }
  83. </style>