|
| 1 | +<template> |
| 2 | + <div class="json-editor"> |
| 3 | + <div ref="diffeditor" class="diff-editor" :style="{height: `${minHeight}px`}" /> |
| 4 | + </div> |
| 5 | +</template> |
| 6 | + |
| 7 | +<script> |
| 8 | +import * as monaco from 'monaco-editor' |
| 9 | +
|
| 10 | +export default { |
| 11 | + name: 'FunctionDiffEditor', |
| 12 | + /* eslint-disable vue/require-prop-types */ |
| 13 | + props: ['original', 'modified', 'height', 'dark', 'name'], |
| 14 | + data() { |
| 15 | + return { |
| 16 | + originalModel: null, |
| 17 | + modifiedModel: null, |
| 18 | + editor: {} |
| 19 | + } |
| 20 | + }, |
| 21 | + computed: { |
| 22 | + minHeight() { |
| 23 | + return this.height || 150 |
| 24 | + } |
| 25 | + }, |
| 26 | + watch: { |
| 27 | + // modified(value) { |
| 28 | + // const editorValue = this.modifiedModel?.getValue() |
| 29 | + // if (value !== editorValue) { |
| 30 | + // console.log(value, editorValue) |
| 31 | + // this.modifiedModel.setValue(this.value) |
| 32 | + // } |
| 33 | + // }, |
| 34 | + height(value) { |
| 35 | + // this.initEditor() |
| 36 | + } |
| 37 | + }, |
| 38 | + mounted() { |
| 39 | + this.initEditor() |
| 40 | + }, |
| 41 | + methods: { |
| 42 | + initEditor() { |
| 43 | + this.originalModel = monaco.editor.createModel(this.original, 'typescript', monaco.Uri.parse(`diff-${Math.random()}.ts`)) |
| 44 | + this.modifiedModel = monaco.editor.createModel(this.modified, 'typescript', monaco.Uri.parse(`diff-${Math.random()}.ts`)) |
| 45 | +
|
| 46 | + this.editor = monaco.editor.createDiffEditor(this.$refs.diffeditor, { |
| 47 | + enableSplitViewResizing: false, |
| 48 | + lineNumbers: 'on', |
| 49 | + roundedSelection: true, |
| 50 | + scrollBeyondLastLine: false, |
| 51 | + theme: this.dark ? 'vs-dark' : 'vs', |
| 52 | + readOnly: true, |
| 53 | + formatOnType: true, |
| 54 | + fontSize: 12, |
| 55 | + linkedEditing: true, |
| 56 | + cursorBlinking: 'expand', |
| 57 | + smoothScrolling: true, |
| 58 | + renderWhitespace: 'selection', |
| 59 | + tabSize: 2, |
| 60 | + automaticLayout: true, |
| 61 | + autoIndent: true, |
| 62 | + showFoldingControls: 'always', |
| 63 | + showDeprecated: true, |
| 64 | + definitionLinkOpensInPeek: false |
| 65 | + }) |
| 66 | +
|
| 67 | + this.editor.setModel({ |
| 68 | + original: this.originalModel, |
| 69 | + modified: this.modifiedModel |
| 70 | + }) |
| 71 | +
|
| 72 | + // this.editor = monaco.editor.create(this.$refs.jseditor, { |
| 73 | + // lineNumbers: 'on', |
| 74 | + // roundedSelection: true, |
| 75 | + // scrollBeyondLastLine: false, |
| 76 | + // theme: this.dark ? 'vs-dark' : 'vs', |
| 77 | + // readOnly: false, |
| 78 | + // formatOnType: true, |
| 79 | + // fontSize: 16, |
| 80 | + // linkedEditing: true, |
| 81 | + // cursorBlinking: 'expand', |
| 82 | + // smoothScrolling: true, |
| 83 | + // renderWhitespace: 'selection', |
| 84 | + // tabSize: 2, |
| 85 | + // automaticLayout: true, |
| 86 | + // autoIndent: true, |
| 87 | + // showFoldingControls: 'always', |
| 88 | + // showDeprecated: true, |
| 89 | + // definitionLinkOpensInPeek: false, |
| 90 | + // model: monaco.editor.createModel(this.value, 'typescript', monaco.Uri.parse(filename)) |
| 91 | + // }) |
| 92 | +
|
| 93 | + // this.editor.onDidChangeModelContent(e => { |
| 94 | + // this.$emit('input', this.editor?.getValue()) |
| 95 | + // this.parseImports(this.getValue()) |
| 96 | + // }) |
| 97 | + } |
| 98 | +
|
| 99 | + // getValue() { |
| 100 | + // return this.editor?.getValue() |
| 101 | + // }, |
| 102 | + } |
| 103 | +} |
| 104 | +</script> |
| 105 | + |
| 106 | +<style lang="scss" scoped> |
| 107 | +.json-editor { |
| 108 | + height: 100%; |
| 109 | + // position: relative; |
| 110 | +
|
| 111 | +.diff-editor { |
| 112 | + width: 100%; |
| 113 | + min-height: 600px; |
| 114 | +} |
| 115 | +} |
| 116 | +</style> |
0 commit comments