ng-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
16 lines (14 loc) • 11.2 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@angular/forms"),require("ng-zorro-antd/core/logger"),require("ng-zorro-antd/core/util"),require("rxjs"),require("rxjs/operators"),require("@angular/common"),require("ng-zorro-antd/core/config"),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","ng-zorro-antd/core/logger","ng-zorro-antd/core/util","rxjs","rxjs/operators","@angular/common","ng-zorro-antd/core/config","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["ng-zorro-antd"].core.logger,t["ng-zorro-antd"].core.util,t.rxjs,t.rxjs.operators,t.ng.common,t["ng-zorro-antd"].core.config,t["ng-zorro-antd"].icon,t["ng-zorro-antd"].spin)}(this,(function(t,e,o,n,i,r,a,s,d,c,u){"use strict";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */var l=function(){return(l=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 p(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 f(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}function h(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 g(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(h(arguments[e]));return t}var m={UNLOAD:"unload",LOADING:"loading",LOADED:"LOADED"};var y=new e.InjectionToken("nz-code-editor-config",{providedIn:"root",factory:v});function v(){return{}}function z(t){return function(){for(var e=[],o=0;o<arguments.length;o++)e[o]=arguments[o];t&&t.apply(void 0,g(e))}}var O=function(){function t(t,e,o){var i=this;this.nzConfigService=t,this.firstEditorInitialized=!1,this.loaded$=new r.Subject,this.loadingStatus=m.UNLOAD,this.option$=new r.BehaviorSubject(this.option);var a=this.nzConfigService.getConfigForComponent("codeEditor");o&&n.warnDeprecation("'NZ_CODE_EDITOR_CONFIG' is deprecated and will be removed in next minor version. Please use 'NzConfigService' instead."),this.document=e,this.config=l(l({},o),a),this.option=this.config.defaultEditorOption||{},this.nzConfigService.getConfigChangeEventForComponent("codeEditor").subscribe((function(){var t=i.nzConfigService.getConfigForComponent("codeEditor");t&&i._updateDefaultOption(t.defaultEditorOption)}))}return t.prototype.updateDefaultOption=function(t){n.warnDeprecation("'updateDefaultOption' is deprecated and will be removed in next minor version. Please use 'set' of 'NzConfigService' instead."),this._updateDefaultOption(t)},t.prototype._updateDefaultOption=function(t){this.option=l(l({},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===m.LOADED?(this.onInit(),r.of(this.getLatestOption())):(this.loadingStatus===m.UNLOAD&&(this.config.useStaticLoading&&"undefined"==typeof monaco?n.warn("You choose to use static loading but it seems that you forget to config webpack plugin correctly. Please refer to our official websitefor more details about static loading."):this.loadMonacoScript()),this.loaded$.asObservable().pipe(a.tap((function(){return t.onInit()})),a.map((function(){return t.getLatestOption()}))))},t.prototype.loadMonacoScript=function(){var t=this;if(this.config.useStaticLoading)this.onLoad();else if(this.loadingStatus!==m.LOADING){this.loadingStatus=m.LOADING;var e=this.config.assetsRoot,o=e?e+"/vs":"assets/vs",i=window,r=this.document.createElement("script");r.type="text/javascript",r.src=o+"/loader.js",r.onload=function(){i.require.config({paths:{vs:o}}),i.require(["vs/editor/editor.main"],(function(){t.onLoad()}))},r.onerror=function(){throw new Error(n.PREFIX+' cannot load assets of monaco editor from source "'+o+'".')},this.document.documentElement.appendChild(r)}},t.prototype.onLoad=function(){this.loadingStatus=m.LOADED,this.loaded$.next(!0),this.loaded$.complete(),z(this.config.onLoad)()},t.prototype.onInit=function(){this.firstEditorInitialized||(this.firstEditorInitialized=!0,z(this.config.onFirstEditorInit)()),z(this.config.onInit)()},t.prototype.getLatestOption=function(){return l({},this.option)},t.decorators=[{type:e.Injectable,args:[{providedIn:"root"}]}],t.ctorParameters=function(){return[{type:d.NzConfigService},{type:void 0,decorators:[{type:e.Inject,args:[s.DOCUMENT]}]},{type:void 0,decorators:[{type:e.Inject,args:[y]},{type:e.Optional}]}]},t.ɵprov=e.ɵɵdefineInjectable({factory:function(){return new t(e.ɵɵinject(d.NzConfigService),e.ɵɵinject(s.DOCUMENT),e.ɵɵinject(y,8))},token:t,providedIn:"root"}),t}();var C=function(){function t(t,o,n){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 r.Subject,this.resize$=new r.Subject,this.editorOption$=new r.BehaviorSubject({}),this.value="",this.modelSet=!1,this.el=n.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.layout=function(){this.resize$.next()},t.prototype.setup=function(t){var e=this;i.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;r.combineLatest([this.editorOption$,this.nzCodeEditorService.option$]).pipe(a.takeUntil(this.destroy$)).subscribe((function(e){var o=h(e,2),n=o[0],i=o[1];t.editorOptionCached=l(l(l({},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,l({},t.editorOptionCached)):monaco.editor.createDiffEditor(t.el,l({},t.editorOptionCached))}))},t.prototype.registerResizeChange=function(){var t=this;this.ngZone.runOutsideAngular((function(){r.fromEvent(window,"resize").pipe(a.debounceTime(300),a.takeUntil(t.destroy$)).subscribe((function(){t.layout()})),t.resize$.pipe(a.takeUntil(t.destroy$),a.filter((function(){return!!t.editorInstance})),a.map((function(){return{width:t.el.clientWidth,height:t.el.clientHeight}})),a.distinctUntilChanged((function(t,e){return t.width===e.width&&t.height===e.height})),a.debounceTime(50)).subscribe((function(){t.editorInstance.layout()}))}))},t.prototype.setValue=function(){if(this.editorInstance)if(this.nzFullControl&&this.value)n.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.nzOriginalText,e),modified:monaco.editor.createModel(this.value,e)}),this.modelSet=!0}},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(l({},this.editorOptionCached))},t.decorators=[{type:e.Component,args:[{changeDetection:e.ChangeDetectionStrategy.OnPush,encapsulation:e.ViewEncapsulation.None,selector:"nz-code-editor",exportAs:"nzCodeEditor",template:'\n <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:O},{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}]},p([i.InputBoolean(),f("design:type",Object)],t.prototype,"nzLoading",void 0),p([i.InputBoolean(),f("design:type",Object)],t.prototype,"nzFullControl",void 0),t}();var I=function(){function t(){}return t.decorators=[{type:e.NgModule,args:[{declarations:[C],imports:[s.CommonModule,c.NzIconModule,u.NzSpinModule],exports:[C]}]}],t}();t.NZ_CODE_EDITOR_CONFIG=y,t.NZ_CODE_EDITOR_CONFIG_FACTORY=v,t.NzCodeEditorComponent=C,t.NzCodeEditorLoadingStatus=m,t.NzCodeEditorModule=I,t.NzCodeEditorService=O,Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=ng-zorro-antd-code-editor.umd.min.js.map