-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
75 lines (70 loc) · 1.57 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const ace = require('brace'),
defaultConfig = {
lang: 'json',
theme: 'xcode',
options: {
useSoftTabs: true,
tabSize: 2
}
};
let vm;
module.exports = {
template: '<div :style="{height: height, width: width}"></div>',
computed: {
editorConfig() {
return Object.assign({}, defaultConfig, this.config);
}
},
props: {
value: {
type: String,
required: true
},
height: true,
width: true,
fontSize: {
type: Number,
default: 12
},
config: {
type: Object,
default: function () {
return defaultConfig
}
}
},
data() {
return {
editor: null
}
},
beforeDestroy: function () {
this.editor.destroy();
this.editor.container.remove();
},
mounted() {
let vm = this,
{
lang,
theme
} = this.editorConfig,
editor;
lang === 'html' && require('brace/ext/emmet');
require('brace/ext/language_tools');
require('brace/mode/' + lang);
require('brace/theme/' + theme);
require('brace/snippets/' + lang);
this.editor = editor = ace.edit(this.$el);
editor.setTheme('ace/theme/' + theme);
editor.setOption("enableEmmet", true);
editor.getSession().setMode('ace/mode/' + lang);
editor.$blockScrolling = Infinity;
editor.setFontSize(this.fontSize);
editor.setValue(this.value);
this.editorConfig.options && editor.setOptions(this.editorConfig.options);
this.$emit('init', editor);
editor.on('change', _ => {
vm.$emit('input', editor.getValue());
});
}
}