<commit_before>import {
  Component,
  OnChanges,
  ViewChild,
  ElementRef,
  EventEmitter,
  Input,
  Output,
  SimpleChange,
} from '@angular/core';

declare var tinymce;

@Component({
  selector: 'minds-textarea',
  template: `
    <div
      #editor
      class="m-editor"
      [ngClass]="{ 'm-editor-disabled': disabled }"
      [attr.contenteditable]="!disabled ? 'true' : null"
      (keyup)="change()"
      (blur)="change()"
      (paste)="paste($event); change()"
    ></div>
    <span
      *ngIf="placeholder && model.length === 0"
      class="m-placeholder"
    >{{ placeholder }}</span>
  `,
  exportAs: "Textarea"
})
  
export class Textarea implements OnChanges {
  @ViewChild('editor') editorControl: ElementRef;

  @Input('mModel') model: string = '';
  @Output('mModelChange') update: EventEmitter<any> = new EventEmitter();

  @Input('disabled') disabled: boolean = false;
  @Input('placeholder') placeholder: string = '';

  getControlText(): string {
    return this.editorControl.nativeElement.innerText;
  }

  setControlText(value: string) {
    this.editorControl.nativeElement.innerText = value; 
  }

  focus() {
    this.editorControl.nativeElement.focus();
  }

  blur() {
    this.editorControl.nativeElement.blur();
  }
  
  change() {
    this.update.emit(this.getControlText());
  }

  paste(e: any) {
    e.preventDefault();

    if (e.clipboardData && e.clipboardData.getData) {
      var text = e.clipboardData.getData("text/plain");
      document.execCommand("insertHTML", false, text);
    } else if ((<any> window).clipboardData && (<any> window).clipboardData.getData) {
      var text = (<any> window).clipboardData.getData("Text");
      this.insertTextAtCursor(text);
    }
  }

  ngOnChanges(changes: { model: SimpleChange, disabled: SimpleChange }) {
    if (
      changes.model &&
      this.getControlText() !== changes.model.currentValue && 
      (
        changes.model.isFirstChange() ||
        changes.model.previousValue !== changes.model.currentValue
      )
    ) {
       this.setControlText(this.model);
    }

    if (changes.disabled && changes.disabled.currentValue) {
      this.blur();<commit_msg>(fix): allow any parameter on ngOnChanges() @ Textarea<commit_after>import {
  Component,
  OnChanges,
  ViewChild,
  ElementRef,
  EventEmitter,
  Input,
  Output,
  SimpleChange,
} from '@angular/core';

declare var tinymce;

@Component({
  selector: 'minds-textarea',
  template: `
    <div
      #editor
      class="m-editor"
      [ngClass]="{ 'm-editor-disabled': disabled }"
      [attr.contenteditable]="!disabled ? 'true' : null"
      (keyup)="change()"
      (blur)="change()"
      (paste)="paste($event); change()"
    ></div>
    <span
      *ngIf="placeholder && model.length === 0"
      class="m-placeholder"
    >{{ placeholder }}</span>
  `,
  exportAs: "Textarea"
})
  
export class Textarea implements OnChanges {
  @ViewChild('editor') editorControl: ElementRef;

  @Input('mModel') model: string = '';
  @Output('mModelChange') update: EventEmitter<any> = new EventEmitter();

  @Input('disabled') disabled: boolean = false;
  @Input('placeholder') placeholder: string = '';

  getControlText(): string {
    return this.editorControl.nativeElement.innerText;
  }

  setControlText(value: string) {
    this.editorControl.nativeElement.innerText = value; 
  }

  focus() {
    this.editorControl.nativeElement.focus();
  }

  blur() {
    this.editorControl.nativeElement.blur();
  }
  
  change() {
    this.update.emit(this.getControlText());
  }

  paste(e: any) {
    e.preventDefault();

    if (e.clipboardData && e.clipboardData.getData) {
      var text = e.clipboardData.getData("text/plain");
      document.execCommand("insertHTML", false, text);
    } else if ((<any> window).clipboardData && (<any> window).clipboardData.getData) {
      var text = (<any> window).clipboardData.getData("Text");
      this.insertTextAtCursor(text);
    }
  }

  ngOnChanges(changes: any) {
    if (
      changes.model &&
      this.getControlText() !== changes.model.currentValue && 
      (
        changes.model.isFirstChange() ||
        changes.model.previousValue !== changes.model.currentValue
      )
    ) {
       this.setControlText(this.model);
    }

    if (changes.disabled && changes.disabled.currentValue) {
      this.blur();
{'fraction_non_alphanumeric': 0.15823515823515824, 'fraction_numerical': 0.000462000462000462, 'mean_word_length': 3.2660098522167487, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2759917', 'n_tokens_mistral': 1392, 'n_tokens_neox': 1349, 'n_words': 238}