|
1 | | -import { CommonModule } from '@angular/common'; |
| 1 | +import {CommonModule} from '@angular/common'; |
2 | 2 | import { |
3 | 3 | AfterViewInit, |
4 | 4 | ChangeDetectionStrategy, |
5 | 5 | ChangeDetectorRef, |
6 | 6 | Component, |
7 | 7 | ElementRef, |
8 | 8 | EventEmitter, |
| 9 | + forwardRef, |
9 | 10 | Input, |
10 | 11 | OnDestroy, |
11 | 12 | Output, |
12 | 13 | ViewChild, |
13 | | - forwardRef, |
14 | 14 | } from '@angular/core'; |
15 | | -import { ControlValueAccessor, FormsModule, NG_VALUE_ACCESSOR } from '@angular/forms'; |
16 | | -import { Jodit } from 'jodit'; |
17 | | -import { BehaviorSubject, Subscription, combineLatest, delay, distinctUntilChanged, filter, withLatestFrom } from 'rxjs'; |
| 15 | +import {ControlValueAccessor, FormsModule, NG_VALUE_ACCESSOR} from '@angular/forms'; |
| 16 | +import {Jodit} from 'jodit'; |
| 17 | +import {BehaviorSubject, combineLatest, delay, distinctUntilChanged, filter, Subscription, withLatestFrom} from 'rxjs'; |
18 | 18 |
|
19 | | -import { JoditConfig } from './types'; |
| 19 | +import {JoditConfig} from './types'; |
20 | 20 |
|
21 | 21 | @Component({ |
22 | 22 | selector: 'ngx-jodit', |
@@ -50,9 +50,14 @@ export class NgxJoditComponent implements ControlValueAccessor, AfterViewInit, O |
50 | 50 |
|
51 | 51 | // value property (subject) |
52 | 52 | private valueSubject: BehaviorSubject<string> = new BehaviorSubject<string>(''); |
| 53 | + |
53 | 54 | @Input() set value(value: string) { |
54 | 55 | const sanitizedText = this.prepareText(value); |
55 | | - this.valueSubject.next(sanitizedText); |
| 56 | + if (!this.internValueChange) { |
| 57 | + this.valueSubject.next(sanitizedText); |
| 58 | + } else { |
| 59 | + this.internValueChange = false; |
| 60 | + } |
56 | 61 | this.onChange(sanitizedText); |
57 | 62 | } |
58 | 63 |
|
@@ -81,6 +86,7 @@ export class NgxJoditComponent implements ControlValueAccessor, AfterViewInit, O |
81 | 86 | // Used for delay value assignment to wait for jodit to be initialized |
82 | 87 | private joditInitializedSubject: BehaviorSubject<boolean> = new BehaviorSubject(false); |
83 | 88 | private valueSubscription?: Subscription; |
| 89 | + private internValueChange = false; |
84 | 90 |
|
85 | 91 | constructor( |
86 | 92 | private readonly cdr: ChangeDetectorRef, |
@@ -131,6 +137,7 @@ export class NgxJoditComponent implements ControlValueAccessor, AfterViewInit, O |
131 | 137 | this.jodit = Jodit.make(this.joditContainer.nativeElement, this._options); |
132 | 138 | this.jodit.value = this.valueSubject.getValue(); |
133 | 139 | this.jodit.events.on('change', (text: string) => { |
| 140 | + this.internValueChange = true; |
134 | 141 | this.changeValue(text); |
135 | 142 | this.joditChange.emit(text); |
136 | 143 | this.onChange(text); |
|
0 commit comments