UNPKG

ng-ace

Version:

An ace editor directive for angular.

143 lines (142 loc) 4.32 kB
import { Directive, ElementRef, EventEmitter, Input, NgModule, Output } from '@angular/core'; var brace = require('brace'); var AceEditorDirective = /** @class */ (function () { /** * @param {?} elementRef */ function AceEditorDirective(elementRef) { var _this = this; this.elementRef = elementRef; this.textChanged = new EventEmitter(); this.editorRef = new EventEmitter(); var el = elementRef.nativeElement; el.classList.add('editor'); this.editor = brace.edit(el); setTimeout(function () { _this.editorRef.emit(_this.editor); }); this.editor.on('change', function () { var newVal = _this.editor.getValue(); if (newVal === _this.oldVal) return; if (typeof _this.oldVal !== 'undefined') { _this.textChanged.emit(newVal); } _this.oldVal = newVal; }); } Object.defineProperty(AceEditorDirective.prototype, "options", { /** * @param {?} value * @return {?} */ set: function (value) { this.editor.setOptions(value || { enableBasicAutocompletion: true, enableLiveAutocompletion: true }); }, enumerable: true, configurable: true }); Object.defineProperty(AceEditorDirective.prototype, "readOnly", { /** * @param {?} value * @return {?} */ set: function (value) { this._readOnly = value; this.editor.setReadOnly(value); }, enumerable: true, configurable: true }); Object.defineProperty(AceEditorDirective.prototype, "theme", { /** * @param {?} value * @return {?} */ set: function (value) { this._theme = value || 'chrome'; this.editor.setTheme("ace/theme/" + value); }, enumerable: true, configurable: true }); Object.defineProperty(AceEditorDirective.prototype, "mode", { /** * @param {?} value * @return {?} */ set: function (value) { this._mode = value || 'javascript'; this.editor.getSession().setMode("ace/mode/" + value); }, enumerable: true, configurable: true }); Object.defineProperty(AceEditorDirective.prototype, "text", { /** * @param {?} value * @return {?} */ set: function (value) { if (value === this.oldVal) return; this.editor.setValue(value); this.editor.clearSelection(); this.editor.focus(); }, enumerable: true, configurable: true }); return AceEditorDirective; }()); AceEditorDirective.decorators = [ { type: Directive, args: [{ selector: '[ace-editor]' },] }, ]; /** * @nocollapse */ AceEditorDirective.ctorParameters = function () { return [ { type: ElementRef, }, ]; }; AceEditorDirective.propDecorators = { 'textChanged': [{ type: Output },], 'editorRef': [{ type: Output },], 'options': [{ type: Input },], 'readOnly': [{ type: Input },], 'theme': [{ type: Input },], 'mode': [{ type: Input },], 'text': [{ type: Input },], }; var AceEditorModule = /** @class */ (function () { function AceEditorModule() { } return AceEditorModule; }()); AceEditorModule.decorators = [ { type: NgModule, args: [{ declarations: [ AceEditorDirective ], exports: [ AceEditorDirective ], providers: [] },] }, ]; /** * @nocollapse */ AceEditorModule.ctorParameters = function () { return []; }; // Copyright (C) 2016-2018 Sergey Akopkokhyants // This project is licensed under the terms of the MIT license. // https://github.com/akserg/ng2-dnd /** * Generated bundle index. Do not edit. */ export { AceEditorDirective, AceEditorModule }; //# sourceMappingURL=ng-ace.es5.js.map