monaco-yaml integration with ngx-monaco-editor-v2

Using Angular 18 (with standalone modules).
The monaco module used is ngx-monaco-editor-v2.

The goal is for the editor to check YAML code against a JSON schema. Works well with JSON with the code below.

app.config.ts

import {
  ApplicationConfig,
  importProvidersFrom,
  provideZoneChangeDetection,
} from '@angular/core';
import { provideRouter } from '@angular/router';

import { routes } from './app.routes';
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
import { MonacoEditorModule } from 'ngx-monaco-editor-v2';
import ParserConfSchema from 'bom-cdm/schemas/parserconf.json';

const onMonacoLoad = () => {
  const monaco = (window as any).monaco;

  monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
    validate: true,
    schemas: [
      {
        uri: 'http://myserver/foo-schema.json',
        fileMatch: ['*'],
        schema: ParserConfSchema,
      },
    ],
  });
};

export const appConfig: ApplicationConfig = {
  providers: [
    provideZoneChangeDetection({ eventCoalescing: true }),
    provideRouter(routes),
    provideAnimationsAsync(),
    importProvidersFrom(
      MonacoEditorModule.forRoot({
        onMonacoLoad: onMonacoLoad,
      })
    ),
  ],
};

conf-editor.component.html

  <ngx-monaco-editor
    [options]="editorOptions"
    [(ngModel)]="data.code"
  ></ngx-monaco-editor>

conf-editor.component.ts

import { Component, Inject } from '@angular/core';
import { MonacoEditorModule } from 'ngx-monaco-editor-v2';
import {
  MAT_DIALOG_DATA,
  MatDialogActions,
  MatDialogClose,
  MatDialogContent,
  MatDialogRef,
  MatDialogTitle,
} from '@angular/material/dialog';
import { FormsModule } from '@angular/forms';
import { MatButtonModule } from '@angular/material/button';

@Component({
  selector: 'app-conf-editor',
  standalone: true,
  imports: [
    MonacoEditorModule,
    MatDialogContent,
    MatDialogActions,
    MatDialogClose,
    MatDialogTitle,
    MonacoEditorModule,
    FormsModule,
    MatButtonModule,
  ],
  templateUrl: './conf-editor.component.html',
  styleUrl: './conf-editor.component.scss',
})
export class ConfEditorComponent {
  editorOptions = { theme: 'vs-dark', language: 'json', automaticLayout: true };

  constructor(
    public dialogRef: MatDialogRef<ConfEditorComponent>,
    @Inject(MAT_DIALOG_DATA)
    public data: {
      name: string;
      code: string;
    }
  ) {}
}

angular.json

...
"assets": [
...
              {
                "glob": "**/*",
                "input": "node_modules/monaco-editor",
                "output": "/assets/monaco/"
              }
...

Now i’m trying to integrate it with monaco-yaml to be able to write yaml code.

To to so, I’ve added
angular.json

...
"assets": [
...
              {
                "glob": "yaml.worker.js",
                "input": "node_modules/monaco-yaml",
                "output": "/assets/monaco-yaml/"
              }

From what I understand, I have to:

  1. Create web workers with something like
  window.MonacoEnvironment = {
    getWorker(moduleId, label) {
      console.log(`getWorker(${moduleId}, ${label})`);
      switch (label) {
        case 'editorWorkerService':
          return new Worker('/assets/monaco/esm/vs/editor/editor.worker.js', {
            type: 'module',
          });
        case 'yaml':
          return new Worker('/assets/monaco-yaml/yaml.worker.js', {
            type: 'module',
          });

        default:
          throw new Error(`Unknown label ${label}`);
      }
    },
  };
  1. Configure the addon
  configureMonacoYaml(monaco, {
    enableSchemaRequest: true,
    schemas: [
      {
        // If YAML file is opened matching this glob
        fileMatch: ['*'],
        // Then this schema will be downloaded from the internet and used.
        uri: 'http://myserver/foo-schema.json',
        schema: ParserConfSchema,
      },
    ],
  });

But doing so I get a string of errors that seems to be related to the WebWorker creation. How to integrate them together?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật