0.1.2 • Published 1 year ago

@zzoysanna/angular-text-editor v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

AngularEditor

A simple native WYSIWYG/Rich Text editor for Angular 6-14+. Forked from @kolkov/angular-editor

Getting Started

Installation

Install via npm package manager

npm install @zoysanna/angular-editor --save

Versions

2.0.0 and above - for Angular v13.0.0 and above

1.0.0 and above - for Angular v8.x.x and above

0.18.4 and above - for Angular v7.x.x

0.15.x - for Angular v6.x.x

Usage

Import angular-editor module

import { HttpClientModule} from '@angular/common/http';
import { AngularEditorModule } from '@zoysanna/angular-editor';

@NgModule({
  imports: [ HttpClientModule, AngularEditorModule ]
})

Then in HTML

<angular-editor [placeholder]="'Enter text here...'" [(ngModel)]="htmlContent"></angular-editor>

or for usage with reactive forms

<angular-editor formControlName="htmlContent" [config]="editorConfig"></angular-editor>

if you using more than one editor on same page set id property

<angular-editor id="editor1" formControlName="htmlContent1" [config]="editorConfig"></angular-editor>
<angular-editor id="editor2" formControlName="htmlContent2" [config]="editorConfig"></angular-editor>

where

import { AngularEditorConfig } from '@zoysanna/angular-editor';


editorConfig: AngularEditorConfig = {
    editable: true,
      spellcheck: true,
      height: 'auto',
      minHeight: '0',
      maxHeight: 'auto',
      width: 'auto',
      minWidth: '0',
      translate: 'yes',
      enableToolbar: true,
      showToolbar: true,
      placeholder: 'Enter text here...',
      defaultParagraphSeparator: '',
      defaultFontName: '',
      defaultFontSize: '',
      fonts: [
        {class: 'arial', name: 'Arial'},
        {class: 'times-new-roman', name: 'Times New Roman'},
        {class: 'calibri', name: 'Calibri'},
        {class: 'comic-sans-ms', name: 'Comic Sans MS'}
      ],
      customClasses: [
      {
        name: 'quote',
        class: 'quote',
      },
      {
        name: 'redText',
        class: 'redText'
      },
      {
        name: 'titleText',
        class: 'titleText',
        tag: 'h1',
      },
    ],
    uploadUrl: 'v1/image',
    upload: (file: File) => { ... }
    uploadWithCredentials: false,
    sanitize: true,
    toolbarPosition: 'top',
    toolbarHiddenButtons: [
      'bold', 'italic',
      'fontSize'
    ],
    buttonTitles: {
      undo: 'Custom undo',
      redo: 'Custom redo',
    }
};

For ngModel to work, you must import FormsModule from @angular/forms, or for formControlName, you must import ReactiveFormsModule from @angular/forms

Custom buttons

You can define your custom buttons with custom actions using executeCommandFn. It accepts commands from execCommand. The first argument of this method is aCommandName and the second argument is aValueArgument. Example shows a button that adds Angular editor logo into the editor.

<angular-editor id="editor1" formControlName="htmlContent1" [config]="editorConfig">
  <ng-template #customButtons let-executeCommandFn="executeCommandFn">
    <ae-toolbar-set>
      <ae-button iconClass="fa fa-html5" title="Angular editor logo"
                 (buttonClick)="executeCommandFn('insertHtml', angularEditorLogo)">
      </ae-button>
    </ae-toolbar-set>
  </ng-template>
</angular-editor>

API

Inputs

InputTypeDefaultRequiredDescription
idstring-noId property when multiple editor used on same page
configAngularEditorConfigdefault confignoconfig for the editor
placeholderstring-noSet custom placeholder for input area
tabIndexnumber-noSet Set tabindex on angular-editor

Outputs

OutputDescription
(html)Output html
(viewMode)Fired when switched visual and html source mode
(blur)Fired when editor blur
(focus)Fired when editor focus

Methods

NameDescription
focusFocuses the editor element

Other

NameTypeDescription
AngularEditorConfigconfigurationConfiguration for the AngularEditor component.

Configuration

InputTypeDefaultRequiredDescription
editablebooleantruenoSet editing enabled or not
spellcheckbooleantruenoSet spellchecking enabled or not
translatestringyesnoSet translating enabled or not
sanitizebooleantruenoSet DOM sanitizing enabled or not
heightstringautonoSet height of the editor
minHeightstring0noSet minimum height of the editor
maxHeightstringautonoSet maximum height of the editor
widthstringautonoSet width of the editor
minWidthstring0noSet minimum width of the editor
enableToolbarbooleantruenoSet toolbar enabled or not
showToolbarbooleantruenoSet toolbar visible or not
toolbarPositionstringtopnoSet toolbar position top or bottom
placeholderstring-noSet placeholder text
defaultParagraphSeparatorstring-noSet default paragraph separator such as p
defaultFontNamestring-noSet default font such as Comic Sans MS
defaultFontSizestring-noSet default font size such as 1 - 7
uploadUrlstring-noSet image upload endpoint https://api.exapple.com/v1/image/upload and return response with imageUrl key. {"imageUrl" : }
uploadfunction-noSet image upload function
uploadWithCredentialsbooleanfalsenoSet passing or not credentials in the image upload call
fontsFont[]-noSet array of available fonts [{name, class},...]
customClassesCustomClass[]-noSet array of available fonts [{name, class, tag},...]
outlinebooleantruenoSet outline of the editor if in focus
toolbarHiddenButtonsstring[][]-noArray of button names or elements to hide
buttonTitlesobject-noObject of custom titles for buttons
toolbarHiddenButtons: [
    'undo',
    'redo',
    'bold',
    'italic',
    'underline',
    'strikeThrough',
    'subscript',
    'superscript',
    'justifyLeft',
    'justifyCenter',
    'justifyRight',
    'justifyFull',
    'indent',
    'outdent',
    'insertUnorderedList',
    'insertOrderedList',
    'heading',
    'fontName',
    'fontSize',
    'textColor',
    'backgroundColor',
    'customClasses',
    'link',
    'unlink',
    'insertImage',
    'insertVideo',
    'insertHorizontalRule',
    'removeFormat',
    'toggleEditorMode'
]

What's included

Within the download you'll find the following directories and files. You'll see something like this:

angular-editor/
└── projects/
    ├── angular-editor/
    └── angular-editor-app/

angular-editor/ - library

angular-editor-app/ - demo application