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

ngx-mat-codemirror

v9.0.2

Published

[![Build Status](https://travis-ci.org/smnbbrv/ngx-mat-codemirror.svg?branch=master)](https://travis-ci.org/smnbbrv/ngx-mat-codemirror)

Downloads

140

Readme

ngx-mat-codemirror

Build Status

A code editor input for Angular Material 2+ based on codemirror.

Demo here.

Installation

npm i -S ngx-mat-codemirror codemirror

and typings for codemirror:

npm i -D @types/codemirror

Configuring styles

First, import node_modules/codemirror/lib/codemirror.css into your project.

Then in order to use standard codemirror themes you need to include the corresponding CSS files. All themes are located at node_modules/codemirror/theme folder.

A preview for the themes could be found here.

For example, if you use angular-cli, add the to your

{
  ...
  "styles": [
    ...,
    "../node_modules/codemirror/lib/codemirror.css",
    "../node_modules/codemirror/theme/neat.css",
    ...,
  ],
  ...
}

This will import the neat codemirror theme and you can use it across the project.

Configuring modes (languages)

Import all the necessary codemirror modes (the languages that you are going to use) in the main.ts or some barrel file that is going to be imported into main.ts.

All the modes could be found at node_modules/codemirror/mode;

For example if we are going to use SASS and YAML code editors then we import the following:

import 'codemirror/mode/sass/sass';
import 'codemirror/mode/yaml/yaml';

Note: it is not enough to import the modes into scripts section of .angular-cli.json.

Usage

Import module whenever you need to use the code editor:

import { NgModule } from '@angular/core';
import { MatCodemirrorModule } from 'ngx-mat-codemirror';

@NgModule({
  // ...
  imports: [
    // ...
    MatCodemirrorModule,
    // ...
  ],
  // ...
})
export class MyModule { }

Then use it:

<mat-card-content>
  <mat-form-field>
    <mat-codemirror formControlName="yaml" required [options]="{ theme: 'neat', mode: 'yaml' }" placeholder="YAML"></mat-codemirror>
    <mat-error *ngIf="form.get('yaml').hasError('required')">required</mat-error>
    <mat-hint>YAML config sample</mat-hint>
  </mat-form-field>
</mat-card-content>

API

The mat-codemirror input implements both ControlValueAccessor and MatFormFieldControl. That means all the properties that are used by / available for

  • ngModel
  • formControl / formControlName
  • material inputs

are also supported here.

Additionally the following properties / events are available:

  • [options] - options passed to the CodeMirror instance. The lineNumbers option will be ignored by design.
  • [name] - name applied to the created textarea
  • [autoFocus] - setting applied to the created textarea
  • [preserveScrollPosition] - preserve previous scroll position after updating value
  • (focusChange) - called when the editor is focused or loses focus
  • (scroll) - called when the editor is scrolled
  • (cursorActivity) - called when the text cursor is moved

Note: the line numbers are automatically shown / hidden depending on the content of the input. If there is more than one line, they are shown, otherwise hidden.

Credits

Credits to @TypeCtrl for initial implementation of ControlValueAccessor

License

MIT