npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@datakitchen/ngx-monaco-editor

v17.0.0

Published

Monaco Editor wrapper for angular applications

Downloads

53

Readme

@datakitchen/ngx-monaco-editor

@datakitchen/ngx-monaco-editor

Microsoft's Monaco editor wrapper for Angular.

Material forms version!

Install

With your package manager of preference, install

@datakitchen/ngx-monaco-editor @monaco-editor/loader monaco-editor

Usage

Import NgxMonacoEditorModule in your app module.

import { NgxMonacoEditorModule } from '@datakitchen/ngx-monaco-editor';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    // Depends on
    BrowserAnimationsModule,
    MatFormFieldModule,
    ReactiveFormsModule,
    // Main module
    NgxMonacoEditorModule,
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

The main module will handle loading of js dependencies for monaco editor.

This package is meant to be used inside an Angular Material <mat-form-field> and used with ReactiveForms, hence it dependes on both.

Use it within an Angular Material form field <mat-form-field>.

<mat-form-field>

  <mat-label>Monaco Editor</mat-label>
  <ngx-monaco-editor [formControl]="formControl"></ngx-monaco-editor>

  <mat-error *ngIf="formControl.hasError('monaco')">Invalid Json</mat-error>
</mat-form-field>

Where formControl is an instance of FormControl. In case the editor goes into an erroneous state, the monaco field of the errors object is set to true. This can be used to show custom error messages with <mat-error>.

import { Component } from '@angular/core';
import { FormControl } from '@angular/forms';

@Component({
  selector: 'app-root',
  styles: [],
  templateUrl: './app.component.html',
})
export class AppComponent {
  title = 'monaco-editor-example';

  formControl = new FormControl<string>('');
}

The component is set to have a minimum height of 200px. You can control this with the css variable --ngx-monaco-editor-min-height, which can be overriden with something like:

:host {
  --ngx-monaco-editor-min-height: 120px;
}

Moncaco editor configuration can be pa By default the editor is set to handle Json. monacoEditor.editor.IEditorOptions can be passed through the NGX_MONACO_EDITOR_CONFIG injectionToken. Such as:

// ...
  providers: [
    {
      provide: NGX_MONACO_EDITOR_CONFIG,
      useValue: {
        language: 'typescript',
        lineNumbers: false,
        // please note that this will override the default values
      }
    }
  ],
// ...

Default values are exported and available from @datakitchen/ngx-monaco-editor:

export const defaultOptions = {
  language: 'json',
  automaticLayout: true,
  lineNumbers: 'off',
  roundedSelection: false,
  scrollBeyondLastLine: false,
  readOnly: false,
  theme: 'vs',
  minimap: {
    enabled: false
  },
  selectOnLineNumbers: true,
  wordWrap: 'on'
};

Refer to Monaco Editor's documentation for details.

Running example app.

We use yarn and suggest to do so if you're planning to contribute or just playing with this code. Following instruction assume you use yarn. Checkout main repo and install dependencies. Build the library with

yarn ng b ngx-monaco-editor

Append --watch while developing. Once that's done run the example app with

yarn ng serve monaco-editor-example