diff --git a/index.js b/index.js new file mode 100644 index 0000000..fd4e44e --- /dev/null +++ b/index.js @@ -0,0 +1,57 @@ +var ace = require('brace'); + +require(['emmet/emmet'],function (data) { + window.emmet = data.emmet; +}); + +module.exports = { + template:"
", + props:{ + content:{ + type:String, + twoWay:true, + required:true + }, + lang:String, + theme:String, + height:true, + width:true + }, + data: function () { + return { + editor:null, + contentBackup:"" + } + }, + methods: {}, + components: {}, + watch:{ + content:function (val) { + if(this.contentBackup !== val) + this.editor.setValue(val,1); + } + }, + ready: function () { + var vm = this; + var lang = this.lang||'text'; + var theme = this.theme||'chrome'; + require('brace/mode/'+lang); + require('brace/theme/'+theme); + require('brace/ext/emmet'); + + var editor = vm.editor = ace.edit(this.$el); + editor.$blockScrolling = Infinity; + editor.setOption("enableEmmet", true); + + editor.getSession().setMode('ace/mode/'+lang); + editor.setTheme('ace/theme/'+theme); + + editor.setValue(this.content,1); + + editor.on('change',function () { + vm.content = editor.getValue(); + vm.contentBackup = vm.content; + }); + + } +} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..f2c3b94 --- /dev/null +++ b/package.json @@ -0,0 +1,23 @@ +{ + "name": "vue-ace-editor", + "version": "1.0.0", + "description": "A Vue's component based on ace/brace", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/chairuosen/vue-ace-editor.git" + }, + "author": "chairuosen", + "license": "MIT", + "bugs": { + "url": "https://github.com/chairuosen/vue-ace-editor/issues" + }, + "homepage": "https://github.com/chairuosen/vue-ace-editor#readme", + "dependencies": { + "brace": "^0.8.0", + "emmet": "git+https://github.com/cloud9ide/emmet-core.git" + } +}