UNPKG

ngx-ace-icy

Version:
2 lines 5.41 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@angular/forms")):"function"==typeof define&&define.amd?define("ngx-ace-icy",["exports","@angular/core","@angular/forms"],e):e((t=t||self)["ngx-ace-icy"]={},t.ng.core,t.ng.forms)}(this,(function(t,e,o){"use strict";var n=function(){function t(t,o){var n=this;this.elementRef=t,this.zone=o,this.textChanged=new e.EventEmitter,this.textChange=new e.EventEmitter,this.placeholder="请输入内容",this.style={},this._options={},this._readOnly=!1,this._theme="monokai",this._mode="sql",this._autoUpdateContent=!0,this._durationBeforeCallback=0,this._text="",this.onChange=function(){return null},this.onTouched=function(){return null};var i=t.nativeElement;this.zone.runOutsideAngular((function(){n._editor=ace.edit(i)})),this._editor.setOptions({enableBasicAutocompletion:!0,enableSnippets:!0,enableLiveAutocompletion:!0,minLines:1,maxLines:1/0}),this._editor.$blockScrolling=1/0,this._editor.setShowPrintMargin(!1)}return 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),t.onChange(e)}))),this.oldText=e,this.emptyMessage())},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){this.onTouched=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()),this.emptyMessage()},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.emptyMessage=function(){var t=!this._text.length,e=this._editor.renderer.emptyMessageNode;!t&&e?(this._editor.renderer.scroller.removeChild(this._editor.renderer.emptyMessageNode),this._editor.renderer.emptyMessageNode=null):t&&!e&&((e=this._editor.renderer.emptyMessageNode=document.createElement("div")).textContent=this.placeholder,e.className="ace_emptyMessage",e.style.padding="0 9px",e.style.position="absolute",e.style.zIndex=9,e.style.opacity=.5,this._editor.renderer.scroller.appendChild(e))},t.prototype.getEditor=function(){return this._editor},t.decorators=[{type:e.Component,args:[{selector:"c-ngx-ace",template:"",providers:[{provide:o.NG_VALUE_ACCESSOR,useExisting:e.forwardRef((function(){return t})),multi:!0}],styles:[":host { display:block;box-sizing: content-box;}"]}]}],t.ctorParameters=function(){return[{type:e.ElementRef},{type:e.NgZone}]},t.propDecorators={textChanged:[{type:e.Output}],textChange:[{type:e.Output}],placeholder:[{type:e.Input}],style:[{type:e.Input}],options:[{type:e.Input}],readOnly:[{type:e.Input}],theme:[{type:e.Input}],mode:[{type:e.Input}],value:[{type:e.Input}],text:[{type:e.Input}],autoUpdateContent:[{type:e.Input}],durationBeforeCallback:[{type:e.Input}]},t}();var i=function(){function t(){}return t.decorators=[{type:e.NgModule,args:[{declarations:[n],imports:[],exports:[n]}]}],t}();t.NgxAceComponent=n,t.NgxAceModule=i,Object.defineProperty(t,"__esModule",{value:!0})})); //# sourceMappingURL=ngx-ace-icy.umd.min.js.map