UNPKG

ng-ace

Version:

An ace editor directive for angular.

148 lines (143 loc) 4.53 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core')) : typeof define === 'function' && define.amd ? define(['exports', '@angular/core'], factory) : (factory((global['ng-ace'] = {}),global.ng.core)); }(this, (function (exports,core) { 'use strict'; var brace = require('brace'); var AceEditorDirective = /** @class */ (function () { /** * @param {?} elementRef */ function AceEditorDirective(elementRef) { var _this = this; this.elementRef = elementRef; this.textChanged = new core.EventEmitter(); this.editorRef = new core.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: core.Directive, args: [{ selector: '[ace-editor]' },] }, ]; /** * @nocollapse */ AceEditorDirective.ctorParameters = function () { return [ { type: core.ElementRef, }, ]; }; AceEditorDirective.propDecorators = { 'textChanged': [{ type: core.Output },], 'editorRef': [{ type: core.Output },], 'options': [{ type: core.Input },], 'readOnly': [{ type: core.Input },], 'theme': [{ type: core.Input },], 'mode': [{ type: core.Input },], 'text': [{ type: core.Input },], }; var AceEditorModule = /** @class */ (function () { function AceEditorModule() { } return AceEditorModule; }()); AceEditorModule.decorators = [ { type: core.NgModule, args: [{ declarations: [ AceEditorDirective ], exports: [ AceEditorDirective ], providers: [] },] }, ]; /** * @nocollapse */ AceEditorModule.ctorParameters = function () { return []; }; exports.AceEditorDirective = AceEditorDirective; exports.AceEditorModule = AceEditorModule; Object.defineProperty(exports, '__esModule', { value: true }); }))); //# sourceMappingURL=ng-ace.umd.js.map