@@ -4,80 +4,66 @@ Add the these dependencies to your ``package.json`` :
4
4
- [ prometheus-community/monaco-promql] ( https://github.com/prometheus-community/monaco-promql )
5
5
6
6
``` bash
7
- npm install ngx- monaco-editor --save
7
+ npm install @ monaco-editor/loader --save
8
8
npm install monaco-promql --save
9
9
```
10
10
11
- Add the glob to assets in your `` angular.json `` configuration file.
11
+ > ** Disclaimer**
12
+ > I didn't manage to make a good plug-and-play integration for Angular.
13
+ > It is a bit a mess but so far it works, modify as you wish and propose enhancements !
12
14
13
- ``` json
14
- {
15
- "projects" : {
16
- "my-project" : {
17
- "architect" : {
18
- "build" : {
19
- "options" : {
20
- "assets" : [
21
- { "glob" : " **/*" , "input" : " ./node_modules/ngx-monaco-editor/assets/monaco" , "output" : " ./assets/monaco/" }
22
- ]
23
- }
24
- }
25
- }
26
- }
27
- }
28
- }
29
- ```
30
-
31
- Integrate the language into the configuration of the angular module.
15
+ - Copy the homemade monaco module from the [ angular example] ( ./../examples/angular-promql/src/app/monaco ) .
16
+ - Mind the version of monaco-editor in the [ MonacoLoaderService] ( ./../examples/angular-promql/src/app/monaco/monaco-loader.service.ts ) .
17
+ It should be the same as the one in your [ package.json] ( ./../examples/angular-promql/package.json ) .
18
+ - Initialize monaco from your main angular module.
32
19
33
20
``` typescript
34
- import { NgModule } from ' @angular/core' ;
35
- import { FormsModule } from ' @angular/forms' ;
36
21
import { BrowserModule } from ' @angular/platform-browser' ;
37
- import { MonacoEditorModule } from ' ngx-monaco-editor ' ;
22
+ import { APP_INITIALIZER , NgModule } from ' @angular/core ' ;
38
23
39
- import { promLanguageDefinition } from ' monaco-promql' ;
40
- import { NgxMonacoEditorConfig } from ' ngx-monaco-editor' ;
24
+ import { AppRoutingModule } from ' ./app-routing.module' ;
41
25
import { AppComponent } from ' ./app.component' ;
42
26
43
- export function onMonacoLoad(): void {
44
- // Register the PromQL language from the library
45
- const languageId = promLanguageDefinition .id ;
46
- monaco .languages .register (promLanguageDefinition );
47
- monaco .languages .onLanguage (languageId , () => {
48
- promLanguageDefinition .loader ().then ((mod ) => {
49
- monaco .languages .setMonarchTokensProvider (languageId , mod .language );
50
- monaco .languages .setLanguageConfiguration (languageId , mod .languageConfiguration );
51
- monaco .languages .registerCompletionItemProvider (languageId , mod .completionItemProvider );
52
- });
53
- });
54
- }
27
+ import { FormsModule } from ' @angular/forms' ;
28
+ import { MonacoStoreService } from ' ./monaco/monaco-store.service' ;
29
+ import { MonacoLoaderService } from ' ./monaco/monaco-loader.service' ;
30
+ import { MonacoModule } from ' ./monaco/monaco.module' ;
55
31
56
- const monacoConfig: NgxMonacoEditorConfig = {
57
- baseUrl: ' assets' , // configure base path for monaco editor default: './assets'
58
- defaultOptions: {scrollBeyondLastLine: false }, // pass default options to be used
59
- onMonacoLoad
60
- };
32
+ function initializeMonaco(loader : MonacoLoaderService , store : MonacoStoreService ): () => Promise <void > {
33
+ return () => {
34
+ return loader .initialize ().then (monaco => {
35
+ loader .registerPromQLLanguage (monaco );
36
+ store .monacoInstance = monaco ;
37
+ });
38
+ };
39
+ }
61
40
62
41
@NgModule ({
63
- declarations: [
64
- AppComponent
65
- ],
66
- imports: [
67
- BrowserModule ,
68
- FormsModule ,
69
- MonacoEditorModule .forRoot (monacoConfig )
70
- ],
71
- providers: [],
72
- bootstrap: [AppComponent ]
42
+ declarations: [
43
+ AppComponent
44
+ ],
45
+ imports: [
46
+ BrowserModule ,
47
+ FormsModule ,
48
+ AppRoutingModule ,
49
+ MonacoModule
50
+ ],
51
+ providers: [
52
+ {
53
+ provide: APP_INITIALIZER ,
54
+ multi: true ,
55
+ deps: [MonacoLoaderService , MonacoStoreService ],
56
+ useFactory: initializeMonaco
57
+ }
58
+ ],
59
+ bootstrap: [AppComponent ]
73
60
})
74
61
export class AppModule {
75
62
}
76
63
```
77
64
78
- Implements now the editor as simply as using the `` ngx -monaco-editor`` component.
65
+ - Implements now the editor as simply as using the `` app -monaco-editor`` component.
79
66
80
67
``` html
81
- <ngx-monaco-editor [options] =" { theme: 'vs-dark', language: 'promql' }"
82
- [(ngModel)] =" sum(http_request_total)" ></ngx-monaco-editor >
68
+ <app-monaco-editor [(ngModel)] =" 'sum(http_request_total)'" ></app-monaco-editor >
83
69
```
0 commit comments