Giter Site home page Giter Site logo

dvmoomoodv / ngx-codemirror Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nomadreservations/ngx-codemirror

0.0 1.0 0.0 1.51 MB

CodeMirror (5.x) code editor in your Angular application. Server Side Rendering(SSR) compliant and @angular 5+ Ready.

Home Page: https://nomadreservations.github.io/ngx-codemirror

License: MIT License

JavaScript 65.22% Shell 2.50% TypeScript 32.28%

ngx-codemirror's Introduction

@nomadreservations/ngx-codemirror

@nomadreservations/ngx-codemirror CodeMirror (5.x) code editor in your Angular application. Server Side Rendering(SSR) compliant and @angular 5+ Ready.

Originally derived from ng2-codemirror

Table of Contents:

1. Installation

To use @nomadreservations/ngx-codemirror in your project install it via npm:

npm i @nomadreservations/ngx-codemirror --save

2. Project structure

  • Library:
    • src folder for the classes
    • public_api.ts entry point for all public APIs of the package
    • package.json npm options
    • rollup.config.js Rollup configuration for building the umd bundles
    • rollup.es.config.js Rollup configuration for building the es2015 bundles
    • tsconfig-build.json ngc compiler options for AoT compilation
    • build.js building process using ShellJS
  • Testing:
    • tests folder for unit & integration tests
    • karma.conf.js Karma configuration that uses webpack to build the tests
    • spec.bundle.js defines the files used by webpack
  • Extra:
    • tslint.json TypeScript linter rules with Codelyzer
    • travis.yml Travis CI configuration

3. Testing

The following command run unit & integration tests that are in the tests folder (you can change the folder in spec.bundle.js file):

yarn test

It also reports coverage using Istanbul.

4. Building

The following command:

yarn build
  • starts TSLint with Codelyzer
  • starts AoT compilation using ngc compiler
  • creates dist folder with all the files of distribution

To test locally the npm package:

yarn pack-lib

Then you can install it in an app to test it:

yarn add [path]@nomadreservations/ngx-codemirror-[version].tgz

5. Publishing

Before publishing the first time:

yarn publish-lib

6. Documentation

To generate the documentation, this project uses compodoc:

yarn docs:watch
yarn compodoc

7. Using the library

7.1. Installing

npm install @nomadreservations/ngx-codemirror --save

Then you need to include base CSS of codemirror located in codemirror/lib/codemirror.css

7.2. Sample

Include CodemirrorModule in your main module :

import { CodemirrorModule } from '@nomadreservations/ngx-codemirror';

@NgModule({
  // ...
  imports:      [
    CodemirrorModule
  ],
  // ...
})
export class AppModule { }
import { Component } from '@angular/core';
import { CodemirrorService } from '@nomadreservations/ngx-codemirror';

@Component({
  selector: 'sample',
  template: `
    <ngx-codemirror [(ngModel)]="code"
      [config]="{...}"
      (focus)="onFocus()"
      (blur)="onBlur()">
    </ngx-codemirror>
  `
})
export class Sample{

  constructor(
    private _codeMirror: CodemirrorService,
  ) { }

  public ngOnInit() {
    this._codeMirror.instance$.subscribe((editor) => {
      console.log(editor.state);
    });
  }
}

7.3. Configuration

7.4. Loading

Using SystemJS configuration

System.config({
    map: {
        '@nomadreservations/ngx-codemirror': 'node_modules/@nomadreservations/ngx-codemirror/bundles/@nomadreservations/ngx-codemirror.umd.js'
    }
});

Angular-CLI

No need to set up anything, just import it in your code.

Rollup or webpack

No need to set up anything, just import it in your code.

Plain JavaScript

Include the umd bundle in your index.html:

<script src="node_modules/@nomadreservations/ngx-codemirror/bundles/@nomadreservations/ngx-codemirror.umd.js"></script>

and use global nomadreservations.ngxCodemirror namespace.

7.5. AoT compilation

The library is compatible with AoT compilation.

8. License

MIT

ngx-codemirror's People

Contributors

paullryan avatar

Watchers

James Cloos avatar

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.