ace-editor-ng9
Version:
A fork from ng2-ace-editor updated to work with Angular 9
16 lines (14 loc) • 9.71 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("brace"),require("brace/theme/monokai"),require("@angular/forms")):"function"==typeof define&&define.amd?define("ace-editor-ng9",["exports","@angular/core","brace","brace/theme/monokai","@angular/forms"],e):e((t=t||self)["ace-editor-ng9"]={},t.ng.core,null,null,t.ng.forms)}(this,(function(t,e,o,n,i){"use strict";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */function r(t,e,o,n){var i,r=arguments.length,s=r<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,o):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,o,n);else for(var u=t.length-1;u>=0;u--)(i=t[u])&&(s=(r<3?i(s):r>3?i(e,o,s):i(e,o))||s);return r>3&&s&&Object.defineProperty(e,o,s),s}function s(t,e){var o="function"==typeof Symbol&&t[Symbol.iterator];if(!o)return t;var n,i,r=o.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(n=r.next()).done;)s.push(n.value)}catch(t){i={error:t}}finally{try{n&&!n.done&&(o=r.return)&&o.call(r)}finally{if(i)throw i.error}}return s}function u(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(s(arguments[e]));return t}var a=function(){function t(t,o){var n=this;this.zone=o,this.textChanged=new e.EventEmitter,this.textChange=new e.EventEmitter,this._options={},this._readOnly=!1,this._theme="monokai",this._mode="html",this._autoUpdateContent=!0,this._durationBeforeCallback=0,this._text="";var i=t.nativeElement;this.zone.runOutsideAngular((function(){n.editor=ace.edit(i)})),this.editor.$blockScrolling=1/0}return t.prototype.ngOnInit=function(){this.init(),this.initEvents()},t.prototype.ngOnDestroy=function(){this.editor.destroy()},t.prototype.init=function(){this.editor.setOptions(this._options||{}),this.editor.setTheme("ace/theme/"+this._theme),this.setMode(this._mode),this.editor.setReadOnly(this._readOnly)},t.prototype.initEvents=function(){var t=this;this.editor.on("change",(function(){return t.updateText()})),this.editor.on("paste",(function(){return t.updateText()}))},t.prototype.updateText=function(){var t=this,e=this.editor.getValue();e!==this.oldText&&(this._durationBeforeCallback?(null!=this.timeoutSaving&&clearTimeout(this.timeoutSaving),this.timeoutSaving=setTimeout((function(){t._text=e,t.zone.run((function(){t.textChange.emit(e),t.textChanged.emit(e)})),t.timeoutSaving=null}),this._durationBeforeCallback)):(this._text=e,this.zone.run((function(){t.textChange.emit(e),t.textChanged.emit(e)}))),this.oldText=e)},Object.defineProperty(t.prototype,"options",{set:function(t){this._options=t,this.editor.setOptions(t||{})},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"readOnly",{set:function(t){this._readOnly=t,this.editor.setReadOnly(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"theme",{set:function(t){this._theme=t,this.editor.setTheme("ace/theme/"+t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"mode",{set:function(t){this.setMode(t)},enumerable:!0,configurable:!0}),t.prototype.setMode=function(t){this._mode=t,"object"==typeof this._mode?this.editor.getSession().setMode(this._mode):this.editor.getSession().setMode("ace/mode/"+this._mode)},Object.defineProperty(t.prototype,"text",{get:function(){return this._text},set:function(t){this.setText(t)},enumerable:!0,configurable:!0}),t.prototype.setText=function(t){this._text!==t&&(null==t&&(t=""),!0===this._autoUpdateContent&&(this._text=t,this.editor.setValue(t),this.editor.clearSelection()))},Object.defineProperty(t.prototype,"autoUpdateContent",{set:function(t){this._autoUpdateContent=t},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"durationBeforeCallback",{set:function(t){this.setDurationBeforeCallback(t)},enumerable:!0,configurable:!0}),t.prototype.setDurationBeforeCallback=function(t){this._durationBeforeCallback=t},Object.defineProperty(t.prototype,"aceEditor",{get:function(){return this.editor},enumerable:!0,configurable:!0}),t.ctorParameters=function(){return[{type:e.ElementRef},{type:e.NgZone}]},r([e.Output()],t.prototype,"textChanged",void 0),r([e.Output()],t.prototype,"textChange",void 0),r([e.Input()],t.prototype,"options",null),r([e.Input()],t.prototype,"readOnly",null),r([e.Input()],t.prototype,"theme",null),r([e.Input()],t.prototype,"mode",null),r([e.Input()],t.prototype,"text",null),r([e.Input()],t.prototype,"autoUpdateContent",null),r([e.Input()],t.prototype,"durationBeforeCallback",null),t=r([e.Directive({selector:"[ace-editor]"})],t)}(),p=function(){function t(t,o){var n=this;this.zone=o,this.textChanged=new e.EventEmitter,this.textChange=new e.EventEmitter,this.style={},this._options={},this._readOnly=!1,this._theme="monokai",this._mode="html",this._autoUpdateContent=!0,this._durationBeforeCallback=0,this._text="",this._onChange=function(t){};var i=t.nativeElement;this.zone.runOutsideAngular((function(){n._editor=ace.edit(i)})),this._editor.$blockScrolling=1/0}var o;return o=t,t.prototype.ngOnInit=function(){this.init(),this.initEvents()},t.prototype.ngOnDestroy=function(){this._editor.destroy()},t.prototype.init=function(){this.setOptions(this._options||{}),this.setTheme(this._theme),this.setMode(this._mode),this.setReadOnly(this._readOnly)},t.prototype.initEvents=function(){var t=this;this._editor.on("change",(function(){return t.updateText()})),this._editor.on("paste",(function(){return t.updateText()}))},t.prototype.updateText=function(){var t=this,e=this._editor.getValue();e!==this.oldText&&(this._durationBeforeCallback?(this.timeoutSaving&&clearTimeout(this.timeoutSaving),this.timeoutSaving=setTimeout((function(){t._text=e,t.zone.run((function(){t.textChange.emit(e),t.textChanged.emit(e)})),t.timeoutSaving=null}),this._durationBeforeCallback)):(this._text=e,this.zone.run((function(){t.textChange.emit(e),t.textChanged.emit(e)})),this._onChange(e)),this.oldText=e)},Object.defineProperty(t.prototype,"options",{set:function(t){this.setOptions(t)},enumerable:!0,configurable:!0}),t.prototype.setOptions=function(t){this._options=t,this._editor.setOptions(t||{})},Object.defineProperty(t.prototype,"readOnly",{set:function(t){this.setReadOnly(t)},enumerable:!0,configurable:!0}),t.prototype.setReadOnly=function(t){this._readOnly=t,this._editor.setReadOnly(t)},Object.defineProperty(t.prototype,"theme",{set:function(t){this.setTheme(t)},enumerable:!0,configurable:!0}),t.prototype.setTheme=function(t){this._theme=t,this._editor.setTheme("ace/theme/"+t)},Object.defineProperty(t.prototype,"mode",{set:function(t){this.setMode(t)},enumerable:!0,configurable:!0}),t.prototype.setMode=function(t){this._mode=t,"object"==typeof this._mode?this._editor.getSession().setMode(this._mode):this._editor.getSession().setMode("ace/mode/"+this._mode)},Object.defineProperty(t.prototype,"value",{get:function(){return this.text},set:function(t){this.setText(t)},enumerable:!0,configurable:!0}),t.prototype.writeValue=function(t){this.setText(t)},t.prototype.registerOnChange=function(t){this._onChange=t},t.prototype.registerOnTouched=function(t){},Object.defineProperty(t.prototype,"text",{get:function(){return this._text},set:function(t){this.setText(t)},enumerable:!0,configurable:!0}),t.prototype.setText=function(t){null==t&&(t=""),this._text!==t&&!0===this._autoUpdateContent&&(this._text=t,this._editor.setValue(t),this._onChange(t),this._editor.clearSelection())},Object.defineProperty(t.prototype,"autoUpdateContent",{set:function(t){this.setAutoUpdateContent(t)},enumerable:!0,configurable:!0}),t.prototype.setAutoUpdateContent=function(t){this._autoUpdateContent=t},Object.defineProperty(t.prototype,"durationBeforeCallback",{set:function(t){this.setDurationBeforeCallback(t)},enumerable:!0,configurable:!0}),t.prototype.setDurationBeforeCallback=function(t){this._durationBeforeCallback=t},t.prototype.getEditor=function(){return this._editor},t.ctorParameters=function(){return[{type:e.ElementRef},{type:e.NgZone}]},r([e.Output()],t.prototype,"textChanged",void 0),r([e.Output()],t.prototype,"textChange",void 0),r([e.Input()],t.prototype,"style",void 0),r([e.Input()],t.prototype,"options",null),r([e.Input()],t.prototype,"readOnly",null),r([e.Input()],t.prototype,"theme",null),r([e.Input()],t.prototype,"mode",null),r([e.Input()],t.prototype,"value",null),r([e.Input()],t.prototype,"text",null),r([e.Input()],t.prototype,"autoUpdateContent",null),r([e.Input()],t.prototype,"durationBeforeCallback",null),t=o=r([e.Component({selector:"ace-editor",template:"",providers:[{provide:i.NG_VALUE_ACCESSOR,useExisting:e.forwardRef((function(){return o})),multi:!0}],styles:[":host { display:block;width:100%; }"]})],t)}(),l=[p,a],h=function(){function t(){}return t=r([e.NgModule({declarations:u(l),imports:[],providers:[],exports:l})],t)}();t.AceEditorComponent=p,t.AceEditorDirective=a,t.AceEditorModule=h,Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=ace-editor-ng9.umd.min.js.map