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

@ngstack/code-editor

v9.0.0

Published

Code editor component for Angular applications.

Downloads

18,276

Readme

@ngstack/code-editor

Code editor component for Angular applications.

Based on the Monaco editor that powers VS Code.

Installing

npm install @ngstack/code-editor

Integrating with Angular CLI project

Import CodeEditorModule into your main application module:

import { CodeEditorModule } from '@ngstack/code-editor';

@NgModule({
  imports: [CodeEditorModule.forRoot()]
})
export class AppModule {}

If you want to use a specific version of the Monaco editor, use editorVersion parameter. If not provided, the component is always going to use the latest version.

@NgModule({
  imports: [
    CodeEditorModule.forRoot({
      editorVersion: '0.44.0'
    })
  ]
})
export class AppModule {}

Update template to use the ngs-code-editor:

<ngs-code-editor [theme]="theme" [codeModel]="model" [options]="options" (valueChanged)="onCodeChanged($event)"></ngs-code-editor>

Update component controller class and provide corresponding properties and events:

export class AppComponent {
  theme = 'vs-dark';

  model: CodeModel = {
    language: 'json',
    uri: 'main.json',
    value: '{}'
  };

  options = {
    contextmenu: true,
    minimap: {
      enabled: true
    }
  };

  onCodeChanged(value) {
    console.log('CODE', value);
  }
}

Input Properties

| Name | Type | Default Value | Description | | --------- | --------- | ------------- | -------------------------------------------------------------- | | theme | string | vs | Editor theme. Supported values: vs, vs-dark or hc-black. | | options | Object | {...} | Editor options. | | readOnly | boolean | false | Toggles readonly state of the editor. | | codeModel | CodeModel | | Source code model. |

The codeModel property holds the value that implements the CodeModel interface:

export interface CodeModel {
  language: string;
  value: string;
  uri: string;

  dependencies?: Array<string>;
  schemas?: Array<{
    uri: string;
    schema: Object;
  }>;
}

Editor Options

For available options see IEditorConstructionOptions docs.

The following options are used by default when Editor Component gets created:

{
  "lineNumbers": true,
  "contextmenu": false,
  "minimap": {
    "enabled": false
  }
}

Output Events

| Name | Argument Type | Description | | ------------ | ------------- | ------------------------------------------------------- | | loaded | | Raised when editor finished loading all its components. | | valueChanged | string | Raised after editor value gets changed. |

Typings

The editor is able to resolve typing libraries when set to the Typescript or Javascript language.

Use dependencies property to provide a list of libraries to resolve

<ngs-code-editor [codeModel]="model" ...> </ngs-code-editor>

And in the controller class:

export class MyEditorComponent {
  codeModel: CodeModel = {
    language: 'typescript',
    uri: 'main.ts',
    value: '',
    dependencies: ['@types/node', '@ngstack/translate', '@ngstack/code-editor']
  };
}

Run your application, it may take a few seconds to resolve dependencies. It is performed in the background (web worker), so you can type your code.

Try pasting the following snippet at runtime:

import { TranslateModule, TranslateService } from '@ngstack/translate';
import { CodeEditorModule } from '@ngstack/code-editor';
import * as fs from 'fs';

export class MyClass {
  constructor(translate: TranslateService) {}
}

You should have all the types resolved and auto-completion working.

JSON schemas

You can associate multiple schemas when working with JSON files.

<ngs-code-editor [codeModel]="model" ...> </ngs-code-editor>

Provide the required schemas like in the example below.

export class MyEditorComponent {
  codeModel: CodeModel = {
    language: 'json',
    uri: 'main.json',
    value: '{ "test": true }',
    schemas: [
      {
        uri: 'http://custom/schema.json',
        schema: {
          type: 'object',
          properties: {
            type: {
              enum: ['button', 'textbox']
            }
          }
        }
      }
    ]
  };
}

The schemas get automatically installed and associated with the corresponding file.

Offline Setup

Editor

You can run the editor in the offline mode with your Angular CLI application using the following steps:

Install the monaco-editor:

npm install monaco-editor

Update the angular.json file and append the following asset rule:

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

Update the main application module and setup the service to use the custom baseUrl when application starts:

import { CodeEditorModule, CodeEditorService } from '@ngstack/code-editor';

@NgModule({
  ...,
  imports: [
    ...,
    CodeEditorModule.forRoot({
      baseUrl: 'assets/monaco'
    })
  ],
  ...
})
export class AppModule {}

Typings Worker

Update the angular.json file and append the following asset rule:

{
  "glob": "**/*.js",
  "input": "../node_modules/@ngstack/code-editor/workers",
  "output": "./assets/workers"
}

Then update the CodeEditorService configuration at the application startup:

@NgModule({
  ...,
  imports: [
    ...,
    CodeEditorModule.forRoot({
      typingsWorkerUrl: 'assets/workers/typings-worker.js'
    })
  ],
  ...
})
export class AppModule {}

Lazy Loading

To enable Lazy Loading use CodeEditorModule.forRoot() in the main application, and CodeEditorModule.forChild() in all lazy-loaded feature modules.

For more details please refer to Lazy Loading Feature Modules