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

ng-simple-editor

v0.0.46

Published

This is a dead simple Angular wysiwyg editor. I made it because I cannot find any editor which has no depencies.

Downloads

8

Readme

Angular Simple Editor

Why

  • I search Angular/Ionic Web editors and I couldn't find simple one. All of them have dependencies like jQury, Bootstrap, Fontawesome, etc.
  • So I made one. It's deadly simple. Easy to edit. No dependencies at all.

Demo

Example code

How to Install

npm install --save ng-simple-editor

How to serve as developer

Serving

  • You need to run two Angular building process. One for App component serving and the other is for editor building.
ng s
ng build ng-simple-editor --watch

Publising

  • Patch version in projects/ng-simple-editor/package.json.
  • And run publish command.
npm run lib:publish

How to Use

How to set up

  • And add NgSimpleEditorModule to AppModule or any where.
import { NgSimpleEditorModule } from 'ng-simple-editor';
@NgModule({
  ...
  imports: [
    NgSimpleEditorModule
  ],
  ...
})
export class AppModule { }

How to use it in template

  • Two-way binding. Don't forget to put 'name' attribute if it is used in form.
<ng-simple-editor [init]="{ cursor: true }" [icons]="true" name="html" [(html)]=" html "></ng-simple-editor>
HTML content: {{ html }}
  • Event handling
<ng-simple-editor #editor></ng-simple-editor>
content: {{ editor.content }}
  • Add buttons.
    • By default, if [buttons] is omitted, then it shows all the possible butttons.
    • You can add indivisual buttons. Order of buttons matters in the order of display.
  <ng-simple-editor #editor
    [buttons]="['bold', 'italic', 'underline', 'fontsize', 'forecolor', 'backcolor', 'highlight', 'link', 'unink', 'table', 'formatblock', 'insertline', 'insertimage', 'orderedlist', 'unorderedlist', 'left', 'center', 'removeformat', 'strike', 'big', 'normal']"
  ></ng-simple-editor>
  content: {{ editor.content }}
  • Display icons instead of text buttons.
    • To display icons, set [icons]="true" on the component.
<ng-simple-editor #editor4 [init]="{ cursor: true }" [icons]="true"></ng-simple-editor>
HTML content: {{ editor4.content }}
  • And put/get HTML into the editor.
  @ViewChild('editor') editor: NgSimpleEditorComponent;
  ngAfterContentInit() {
    this.editor.putContent(`<h1>Let's Edit!</h1>`);
  }
  /**
   * Get the HTML of editor
   */
  const html = this.editorComponent.getContent();
  • There is another handy way to insert HTML into editor. When the component is created dynamically using *ngIf=" ... ", it is not easy to know when @ViewChild() editor: EditComponet; is ready to use editor.putContent(). It often causes calling putContent() of undefined. In this case you can use [init] property to insert the default HTML content into editor.
<ng-simple-editor #editor *ngIf=" mode != 'fake' "
  [init]=" { content: comment.content_original }"
  [buttons]="['bold', 'italic', 'unerline', 'fontname', 'fontsize', 'forecolor', 'backcolor', 'highlight', 'link', 'unink', 'table', 'formatblock', 'insertline', 'insertimage', 'orderedlist', 'unorderedlist', 'left', 'center', 'right', 'removeformat', 'strike', 'big', 'normal']"
></ng-simple-editor>
  • How to set cursor. For post writing, you will need to put cursor on subject input tag. For comment write/edit, you will need to put cursor on editor.
      <ng-simple-editor #editorComponent *ngIf=" mode != 'fake' "
        [init]=" { content: comment?.content_original, cursor: true }"
        [buttons]="['bold', ..., 'normal']"
      ></ng-simple-editor>

Buttons

  • Buttons on editor appears in the order of that they were given in [buttons] property.

  • Name of buttons

'bold' | 'italic' | 'underline' | 'fontsize' | 'forecolor' | 'backcolor' | 'highlight' | 'link' | 'unlink' | 'table' | 'fontname' | 'formatblock' | 'indent' | 'outdent' | 'insertline' | 'insertimage' | 'orderedlist' | 'unorderedlist' | 'left' | 'center' | 'right' | 'removeformat' | 'strke' | 'big' | 'normal'

Events

change event on content changes

<ng-simple-editor #editor (change)=" onChange( $event ) "></ng-simple-editor>
  • If you are going to use event parameter from editor, it may contain not only the content but also other event. So, if you want to handle with the content of the ditor, use this.editor.content instead.
  onChange(event: Event) {
    this.content = this.editor.content;
  }

Init options

  • content (string) - initial content. It may be overwritten by two-way binding. Default empty string.
  • cursor (boolean) - to put cursor inside editor. Default false.
  • menuTop (boolean) - to show menu buttons on top. Default true.
  • menuBottom (boolean) - to show menu buttons at bottom. Default true.

How to upload files

  • ng-simple-editor does not have file/photo/video upload functionaliy. You have to make your own file upload function in your app. And then you can insert your uploaded file into editor using editor.insertImage() method.

Design

  • ViewEncapsulation.None is set on the NgSimpleEditorComponent.
  • DOM structure
div.editor
  div.buttons
  div.content
  • Example of auto grow for editor content. You may remove [+] and [-] button in this case.
.editor {
    .content {
        height: auto !important;
        min-height: 120px;
        max-height: 200px;
    }
}

Tips

  • On mobile, it is not easy selecting texts and apply HTML. So, in mobile, you may show only thoese buttons that does not require text selection like format, left, center, right, ol, ul, etc.

Todo

Bug report