ng-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
149 lines • 21.8 kB
JavaScript
/**
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
*/
import { DOCUMENT } from '@angular/common';
import { Inject, Injectable } from '@angular/core';
import { BehaviorSubject, of, ReplaySubject } from 'rxjs';
import { map, tap } from 'rxjs/operators';
import { PREFIX, warn } from 'ng-zorro-antd/core/logger';
import * as i0 from "@angular/core";
import * as i1 from "ng-zorro-antd/core/config";
const NZ_CONFIG_MODULE_NAME = 'codeEditor';
function tryTriggerFunc(fn) {
return (...args) => {
if (fn) {
fn(...args);
}
};
}
// Caretaker note: previously, these were `NzCodeEditorService` properties.
// They're kept as static variables because this will allow loading Monaco only once.
// This applies to micro frontend apps with multiple Angular apps or a single Angular app
// that can be bootstrapped and destroyed multiple times (e.g. using Webpack module federation).
// Root providers are re-initialized each time the app is bootstrapped. Platform providers aren't.
// We can't make the `NzCodeEditorService` to be a platform provider (`@Injectable({ providedIn: 'platform' })`)
// since it depends on other root providers.
const loaded$ = new ReplaySubject(1);
let loadingStatus = "unload" /* NzCodeEditorLoadingStatus.UNLOAD */;
export class NzCodeEditorService {
constructor(nzConfigService, _document) {
this.nzConfigService = nzConfigService;
this.firstEditorInitialized = false;
this.option = {};
this.option$ = new BehaviorSubject(this.option);
const globalConfig = this.nzConfigService.getConfigForComponent(NZ_CONFIG_MODULE_NAME);
this.document = _document;
this.config = { ...globalConfig };
if (this.config.monacoEnvironment) {
window.MonacoEnvironment = { ...this.config.monacoEnvironment };
}
this.option = this.config.defaultEditorOption || {};
this.subscription = this.nzConfigService.getConfigChangeEventForComponent(NZ_CONFIG_MODULE_NAME).subscribe(() => {
const newGlobalConfig = this.nzConfigService.getConfigForComponent(NZ_CONFIG_MODULE_NAME);
if (newGlobalConfig) {
this._updateDefaultOption(newGlobalConfig.defaultEditorOption);
}
});
}
ngOnDestroy() {
this.subscription.unsubscribe();
this.subscription = null;
}
_updateDefaultOption(option) {
this.option = { ...this.option, ...option };
this.option$.next(this.option);
if ('theme' in option && option.theme) {
monaco.editor.setTheme(option.theme);
}
}
requestToInit() {
if (loadingStatus === "LOADED" /* NzCodeEditorLoadingStatus.LOADED */) {
this.onInit();
return of(this.getLatestOption());
}
if (loadingStatus === "unload" /* NzCodeEditorLoadingStatus.UNLOAD */) {
if (this.config.useStaticLoading && typeof monaco === 'undefined') {
warn('You choose to use static loading but it seems that you forget ' +
'to config webpack plugin correctly. Please refer to our official website' +
'for more details about static loading.');
}
else {
this.loadMonacoScript();
}
}
return loaded$.pipe(tap(() => this.onInit()), map(() => this.getLatestOption()));
}
loadMonacoScript() {
if (this.config.useStaticLoading) {
Promise.resolve().then(() => this.onLoad());
return;
}
if (loadingStatus === "loading" /* NzCodeEditorLoadingStatus.LOADING */) {
return;
}
loadingStatus = "loading" /* NzCodeEditorLoadingStatus.LOADING */;
const assetsRoot = this.config.assetsRoot;
const vs = assetsRoot ? `${assetsRoot}/vs` : 'assets/vs';
const windowAsAny = window;
const loadScript = this.document.createElement('script');
loadScript.type = 'text/javascript';
loadScript.src = `${vs}/loader.js`;
const onLoad = () => {
cleanup();
windowAsAny.require.config({
paths: { vs },
...this.config.extraConfig
});
windowAsAny.require(['vs/editor/editor.main'], () => {
this.onLoad();
});
};
const onError = () => {
cleanup();
throw new Error(`${PREFIX} cannot load assets of monaco editor from source "${vs}".`);
};
const cleanup = () => {
// Caretaker note: we have to remove these listeners once the `<script>` is loaded successfully
// or not since the `onLoad` listener captures `this`, which will prevent the `NzCodeEditorService`
// from being garbage collected.
loadScript.removeEventListener('load', onLoad);
loadScript.removeEventListener('error', onError);
// We don't need to keep the `<script>` element within the `<body>` since JavaScript has
// been executed and Monaco is available globally. E.g. Webpack, always removes `<script>`
// elements after loading chunks (see its `LoadScriptRuntimeModule`).
this.document.documentElement.removeChild(loadScript);
};
loadScript.addEventListener('load', onLoad);
loadScript.addEventListener('error', onError);
this.document.documentElement.appendChild(loadScript);
}
onLoad() {
loadingStatus = "LOADED" /* NzCodeEditorLoadingStatus.LOADED */;
loaded$.next(true);
loaded$.complete();
tryTriggerFunc(this.config.onLoad)();
}
onInit() {
if (!this.firstEditorInitialized) {
this.firstEditorInitialized = true;
tryTriggerFunc(this.config.onFirstEditorInit)();
}
tryTriggerFunc(this.config.onInit)();
}
getLatestOption() {
return { ...this.option };
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.4", ngImport: i0, type: NzCodeEditorService, deps: [{ token: i1.NzConfigService }, { token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable }); }
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.3.4", ngImport: i0, type: NzCodeEditorService, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.4", ngImport: i0, type: NzCodeEditorService, decorators: [{
type: Injectable,
args: [{
providedIn: 'root'
}]
}], ctorParameters: () => [{ type: i1.NzConfigService }, { type: undefined, decorators: [{
type: Inject,
args: [DOCUMENT]
}] }] });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29kZS1lZGl0b3Iuc2VydmljZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL2NvbXBvbmVudHMvY29kZS1lZGl0b3IvY29kZS1lZGl0b3Iuc2VydmljZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7O0dBR0c7QUFFSCxPQUFPLEVBQUUsUUFBUSxFQUFFLE1BQU0saUJBQWlCLENBQUM7QUFDM0MsT0FBTyxFQUFFLE1BQU0sRUFBRSxVQUFVLEVBQWEsTUFBTSxlQUFlLENBQUM7QUFDOUQsT0FBTyxFQUFFLGVBQWUsRUFBYyxFQUFFLEVBQUUsYUFBYSxFQUFnQixNQUFNLE1BQU0sQ0FBQztBQUN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