ng-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
2 lines • 9.09 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@angular/forms"),require("rxjs"),require("rxjs/operators"),require("ng-zorro-antd/core"),require("@angular/common"),require("ng-zorro-antd/icon"),require("ng-zorro-antd/spin")):"function"==typeof define&&define.amd?define("ng-zorro-antd/code-editor",["exports","@angular/core","@angular/forms","rxjs","rxjs/operators","ng-zorro-antd/core","@angular/common","ng-zorro-antd/icon","ng-zorro-antd/spin"],e):e(((t=t||self)["ng-zorro-antd"]=t["ng-zorro-antd"]||{},t["ng-zorro-antd"]["code-editor"]={}),t.ng.core,t.ng.forms,t.rxjs,t.rxjs.operators,t["ng-zorro-antd"].core,t.ng.common,t["ng-zorro-antd"].icon,t["ng-zorro-antd"].spin)}(this,function(t,e,o,n,i,r,a,s,d){"use strict";var c=function(){return(c=Object.assign||function(t){for(var e,o=1,n=arguments.length;o<n;o++)for(var i in e=arguments[o])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function u(t,e,o,n){var i,r=arguments.length,a=r<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,o):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,o,n);else for(var s=t.length-1;s>=0;s--)(i=t[s])&&(a=(r<3?i(a):r>3?i(e,o,a):i(e,o))||a);return r>3&&a&&Object.defineProperty(e,o,a),a}function l(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}function p(t,e){var o="function"==typeof Symbol&&t[Symbol.iterator];if(!o)return t;var n,i,r=o.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(n=r.next()).done;)a.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 a}function h(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(p(arguments[e]));return t}var f={UNLOAD:"unload",LOADING:"loading",LOADED:"LOADED"};var g=new e.InjectionToken("nz-code-editor-config",{providedIn:"root",factory:y});function y(){return{}}function m(t){return function(){for(var e=[],o=0;o<arguments.length;o++)e[o]=arguments[o];t&&t.apply(void 0,h(e))}}var v=function(){function t(t,e){this.config=t,this.firstEditorInitialized=!1,this.loaded$=new n.Subject,this.loadingStatus=f.UNLOAD,this.option$=new n.BehaviorSubject(this.option),this.document=e,this.option=this.config.defaultEditorOption||{}}return t.prototype.updateDefaultOption=function(t){this.option=c({},this.option,t),this.option$.next(this.option),t.theme&&monaco.editor.setTheme(t.theme)},t.prototype.requestToInit=function(){var t=this;return this.loadingStatus===f.LOADED?(this.onInit(),n.of(this.getLatestOption())):(this.loadingStatus===f.UNLOAD&&this.loadMonacoScript(),this.loaded$.asObservable().pipe(i.tap(function(){return t.onInit()}),i.map(function(){return t.getLatestOption()})))},t.prototype.loadMonacoScript=function(){var t=this;if(this.loadingStatus!==f.LOADING){this.loadingStatus=f.LOADING;var e=this.config.assetsRoot,o=e?e+"/vs":"assets/vs",n=window,i=this.document.createElement("script");i.type="text/javascript",i.src=o+"/loader.js",i.onload=function(){n.require.config({paths:{vs:o}}),n.require(["vs/editor/editor.main"],function(){t.loadingStatus=f.LOADED,t.loaded$.next(!0),t.loaded$.complete(),t.onLoad()})},i.onerror=function(){throw new Error(r.PREFIX+' cannot load assets of monaco editor from source "'+o+'".')},this.document.documentElement.appendChild(i)}},t.prototype.onInit=function(){this.firstEditorInitialized||(this.firstEditorInitialized=!0,m(this.config.onFirstEditorInit)()),m(this.config.onInit)()},t.prototype.onLoad=function(){m(this.config.onLoad)()},t.prototype.getLatestOption=function(){return c({},this.option)},t.decorators=[{type:e.Injectable,args:[{providedIn:"root"}]}],t.ctorParameters=function(){return[{type:void 0,decorators:[{type:e.Inject,args:[g]}]},{type:void 0,decorators:[{type:e.Inject,args:[a.DOCUMENT]}]}]},t.ngInjectableDef=e.ɵɵdefineInjectable({factory:function(){return new t(e.ɵɵinject(g),e.ɵɵinject(a.DOCUMENT))},token:t,providedIn:"root"}),t}();var O=function(){function t(t,o,i){this.nzCodeEditorService=t,this.ngZone=o,this.nzEditorMode="normal",this.nzOriginalText="",this.nzLoading=!1,this.nzFullControl=!1,this.nzEditorInitialized=new e.EventEmitter,this.editorOptionCached={},this.destroy$=new n.Subject,this.resize$=new n.Subject,this.editorOption$=new n.BehaviorSubject({}),this.value="",this.modelSet=!1,this.el=i.nativeElement}return Object.defineProperty(t.prototype,"nzEditorOption",{set:function(t){this.editorOption$.next(t)},enumerable:!0,configurable:!0}),t.prototype.ngAfterViewInit=function(){var t=this;this.nzCodeEditorService.requestToInit().subscribe(function(e){return t.setup(e)})},t.prototype.ngOnDestroy=function(){this.editorInstance&&this.editorInstance.dispose(),this.destroy$.next(),this.destroy$.complete()},t.prototype.writeValue=function(t){this.value=t,this.setValue()},t.prototype.registerOnChange=function(t){this.onChange=t},t.prototype.registerOnTouched=function(t){this.onTouch=t},t.prototype.onChange=function(t){},t.prototype.onTouch=function(){},t.prototype.layout=function(){this.resize$.next()},t.prototype.setup=function(t){var e=this;r.inNextTick().subscribe(function(){e.editorOptionCached=t,e.registerOptionChanges(),e.initMonacoEditorInstance(),e.registerResizeChange(),e.setValue(),e.nzFullControl||e.setValueEmitter(),e.nzEditorInitialized.emit(e.editorInstance)})},t.prototype.registerOptionChanges=function(){var t=this;n.combineLatest([this.editorOption$,this.nzCodeEditorService.option$]).pipe(i.takeUntil(this.destroy$)).subscribe(function(e){var o=p(e,2),n=o[0],i=o[1];t.editorOptionCached=c({},t.editorOptionCached,i,n),t.updateOptionToMonaco()})},t.prototype.initMonacoEditorInstance=function(){var t=this;this.ngZone.runOutsideAngular(function(){t.editorInstance="normal"===t.nzEditorMode?monaco.editor.create(t.el,c({},t.editorOptionCached)):monaco.editor.createDiffEditor(t.el,c({},t.editorOptionCached))})},t.prototype.registerResizeChange=function(){var t=this;this.ngZone.runOutsideAngular(function(){n.fromEvent(window,"resize").pipe(i.debounceTime(300),i.takeUntil(t.destroy$)).subscribe(function(){t.layout()}),t.resize$.pipe(i.takeUntil(t.destroy$),i.filter(function(){return!!t.editorInstance}),i.map(function(){return{width:t.el.clientWidth,height:t.el.clientHeight}}),i.distinctUntilChanged(function(t,e){return t.width===e.width&&t.height===e.height}),i.debounceTime(50)).subscribe(function(){t.editorInstance.layout()})})},t.prototype.setValue=function(){if(this.editorInstance)if(this.nzFullControl&&this.value)r.warn("should not set value when you are using full control mode! It would result in ambiguous data flow!");else if("normal"===this.nzEditorMode)this.modelSet?this.editorInstance.getModel().setValue(this.value):(this.editorInstance.setModel(monaco.editor.createModel(this.value,this.editorOptionCached.language)),this.modelSet=!0);else if(this.modelSet){var t=this.editorInstance.getModel();t.modified.setValue(this.value),t.original.setValue(this.nzOriginalText)}else{var e=this.editorOptionCached.language;this.editorInstance.setModel({original:monaco.editor.createModel(this.value,e),modified:monaco.editor.createModel(this.nzOriginalText,e)})}},t.prototype.setValueEmitter=function(){var t=this,e="normal"===this.nzEditorMode?this.editorInstance.getModel():this.editorInstance.getModel().modified;e.onDidChangeContent(function(){t.emitValue(e.getValue())})},t.prototype.emitValue=function(t){this.value=t,this.onChange(t)},t.prototype.updateOptionToMonaco=function(){this.editorInstance&&this.editorInstance.updateOptions(c({},this.editorOptionCached))},t.decorators=[{type:e.Component,args:[{changeDetection:e.ChangeDetectionStrategy.OnPush,encapsulation:e.ViewEncapsulation.None,selector:"nz-code-editor",exportAs:"nzCodeEditor",template:'<div class="ant-code-editor-loading" *ngIf="nzLoading">\n <nz-spin></nz-spin>\n</div>\n\n<div class="ant-code-editor-toolkit" *ngIf="nzToolkit">\n <ng-template [ngTemplateOutlet]="nzToolkit"></ng-template>\n</div>\n',host:{"[class.ant-code-editor]":"true"},providers:[{provide:o.NG_VALUE_ACCESSOR,useExisting:e.forwardRef(function(){return t}),multi:!0}]}]}],t.ctorParameters=function(){return[{type:v},{type:e.NgZone},{type:e.ElementRef}]},t.propDecorators={nzEditorMode:[{type:e.Input}],nzOriginalText:[{type:e.Input}],nzLoading:[{type:e.Input}],nzFullControl:[{type:e.Input}],nzToolkit:[{type:e.Input}],nzEditorOption:[{type:e.Input}],nzEditorInitialized:[{type:e.Output}]},u([r.InputBoolean(),l("design:type",Object)],t.prototype,"nzLoading",void 0),u([r.InputBoolean(),l("design:type",Object)],t.prototype,"nzFullControl",void 0),t}();var z=function(){function t(){}return t.decorators=[{type:e.NgModule,args:[{declarations:[O],imports:[a.CommonModule,s.NzIconModule,d.NzSpinModule],exports:[O]}]}],t}();t.NZ_CODE_EDITOR_CONFIG=g,t.NZ_CODE_EDITOR_CONFIG_FACTORY=y,t.NzCodeEditorComponent=O,t.NzCodeEditorLoadingStatus=f,t.NzCodeEditorModule=z,t.NzCodeEditorService=v,Object.defineProperty(t,"__esModule",{value:!0})});
//# sourceMappingURL=ng-zorro-antd-code-editor.umd.min.js.map