GithubHelp home page GithubHelp logo

alauda / ng-monaco-editor Goto Github PK

View Code? Open in Web Editor NEW
29.0 16.0 5.0 23.18 MB

Angular wrapper for monaco-editor.

Home Page: https://ng-monaco-editor.netlify.app

License: MIT License

TypeScript 94.37% JavaScript 0.58% HTML 1.66% SCSS 3.39%
monaco-editor angular ng

ng-monaco-editor's Introduction

Angular wrapper for monaco-editor

GitHub Release Workflow Status GitHub Stories Workflow Status npm

Dependencies

Demo

See: https://ng-monaco-editor.js.org or https://ng-monaco-editor.netlify.app

Setup

Add npm dependencies

# npm
npm i monaco-editor ng-monaco-editor

# yarn
yarn add monaco-editor ng-monaco-editor

Configure monaco-editor library assets

It's supported to load monaco-editor with AMD or ESM mode.

If you'd like to use AMD mode, you have to make sure your Angular application could have access to the monaco-editor library assets via AMD. If you are using Angular CLI to bootstrap your app, you could add the following:

{
  "assets": [
    "src/favicon.ico",
    "src/assets",

    {
      "glob": "**/*",
      "input": "node_modules/monaco-editor/min/vs",
      "output": "/lib/vs"
    }
  ]
}

Load ng-monaco-editor module

Most of the time, you should configure the module at the root module.

@NgModule({
  declarations: [AppComponent],
  imports: [
    BrowserModule,
    FormsModule,
    MonacoEditorModule.forRoot({
      /**
       * optional, load monaco by yourself, you'd prefer loading esm for example
       */
      dynamicImport: () => import('monaco-editor'),

      /**
       * optional, use amd loader to load monaco if present, lower priority than `dynamicImport`
       *
       * Angular CLI currently does not handle assets with hashes. We manage it by manually adding
       * version numbers to force library updates:
       */
      baseUrl: 'lib/v1',

      defaultOptions: {},
    }),
  ],
  providers: [
    {
      // Optional:
      // You could also override the default MonacoEditor provider.
      // If you plan to do so, I recommend you to read through the source code.
      provide: MonacoProviderService,
      useClass: CustomMonacoProviderService,
    },
  ],
  bootstrap: [AppComponent],
})
export class AppModule {}

Usage example

Please refer to the storybook (stories/**/*.stories.ts).

This module provide three usages:

  1. ng-monaco-editor component
  2. ng-monaco-diff-editor component
  3. ngCodeColorize directive

Note, if the height of ng-monaco-editor/ng-monaco-diff-editor is too small, you may have to resize it yourself. This is a limitation and by design that how monaco-editor works.

License

MIT @Alauda

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.