Skip to content

Commit

Permalink
fix: don't return values from writeValue
Browse files Browse the repository at this point in the history
closes #78
  • Loading branch information
sibiraj-s committed Mar 11, 2018
1 parent 182152a commit 36133e1
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 138 deletions.
200 changes: 102 additions & 98 deletions docs/components/NgxEditorComponent.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/components/NgxEditorToolbarComponent.html
Original file line number Diff line number Diff line change
Expand Up @@ -1651,7 +1651,7 @@ <h3 id="inputs">
<div class="tab-pane fade tab-source-code" id="c-source">
<pre class="line-numbers compodoc-sourcecode"><code class="language-typescript">import { Component, Input, Output, EventEmitter, OnInit, ViewChild } from &#x27;@angular/core&#x27;;
import { FormBuilder, FormGroup, Validators } from &#x27;@angular/forms&#x27;;
import { HttpEvent, HttpEventType, HttpResponse } from &#x27;@angular/common/http&#x27;;
import { HttpResponse } from &#x27;@angular/common/http&#x27;;
import { PopoverConfig } from &#x27;ngx-bootstrap&#x27;;
import { CommandExecutorService } from &#x27;../common/services/command-executor.service&#x27;;
import { MessageService } from &#x27;../common/services/message.service&#x27;;
Expand Down
2 changes: 1 addition & 1 deletion docs/components/NgxGrippieComponent.html
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ <h3 id="inputs">


<div class="tab-pane fade tab-source-code" id="c-source">
<pre class="line-numbers compodoc-sourcecode"><code class="language-typescript">import { Component, OnInit, HostListener } from &#x27;@angular/core&#x27;;
<pre class="line-numbers compodoc-sourcecode"><code class="language-typescript">import { Component, HostListener } from &#x27;@angular/core&#x27;;
import { NgxEditorComponent } from &#x27;../ngx-editor.component&#x27;;

@Component({
Expand Down
39 changes: 10 additions & 29 deletions docs/injectables/CommandExecutorService.html
Original file line number Diff line number Diff line change
Expand Up @@ -466,12 +466,12 @@ <h3 id="constructor">Constructor</h3>
<tbody>
<tr>
<td class="col-md-4">
<code>constructor(_http: <a href="https://angular.io/api/common/http/HttpClient" target="_blank">HttpClient</a>, _messageService: <a href="../injectables/MessageService.html">MessageService</a>)</code>
<code>constructor(_http: <a href="https://angular.io/api/common/http/HttpClient" target="_blank">HttpClient</a>)</code>
</td>
</tr>
<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="11" class="link-to-prism">src/app/ngx-editor/common/services/command-executor.service.ts:11</a></div>
<div class="io-line">Defined in <a href="" data-line="9" class="link-to-prism">src/app/ngx-editor/common/services/command-executor.service.ts:9</a></div>
</td>
</tr>

Expand Down Expand Up @@ -502,22 +502,6 @@ <h3 id="constructor">Constructor</h3>

<td>
<code><p>HTTP Client for making http requests</p>
</code>
</td>
</tr>
<tr>
<td>_messageService</td>

<td>
<code><a href="../injectables/MessageService.html" target="_self" >MessageService</a></code>
</td>

<td>
no
</td>

<td>
<code><p>Message service sends message to the editor</p>
</code>
</td>
</tr>
Expand Down Expand Up @@ -557,7 +541,7 @@ <h3 id="methods">

<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="101" class="link-to-prism">src/app/ngx-editor/common/services/command-executor.service.ts:101</a></div>
<div class="io-line">Defined in <a href="" data-line="98" class="link-to-prism">src/app/ngx-editor/common/services/command-executor.service.ts:98</a></div>
</td>
</tr>

Expand Down Expand Up @@ -633,7 +617,7 @@ <h3 id="methods">

<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="25" class="link-to-prism">src/app/ngx-editor/common/services/command-executor.service.ts:25</a></div>
<div class="io-line">Defined in <a href="" data-line="22" class="link-to-prism">src/app/ngx-editor/common/services/command-executor.service.ts:22</a></div>
</td>
</tr>

Expand Down Expand Up @@ -709,7 +693,7 @@ <h3 id="methods">

<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="134" class="link-to-prism">src/app/ngx-editor/common/services/command-executor.service.ts:134</a></div>
<div class="io-line">Defined in <a href="" data-line="131" class="link-to-prism">src/app/ngx-editor/common/services/command-executor.service.ts:131</a></div>
</td>
</tr>

Expand Down Expand Up @@ -793,7 +777,7 @@ <h3 id="methods">

<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="50" class="link-to-prism">src/app/ngx-editor/common/services/command-executor.service.ts:50</a></div>
<div class="io-line">Defined in <a href="" data-line="47" class="link-to-prism">src/app/ngx-editor/common/services/command-executor.service.ts:47</a></div>
</td>
</tr>

Expand Down Expand Up @@ -869,7 +853,7 @@ <h3 id="methods">

<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="154" class="link-to-prism">src/app/ngx-editor/common/services/command-executor.service.ts:154</a></div>
<div class="io-line">Defined in <a href="" data-line="151" class="link-to-prism">src/app/ngx-editor/common/services/command-executor.service.ts:151</a></div>
</td>
</tr>

Expand Down Expand Up @@ -940,7 +924,7 @@ <h3 id="methods">

<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="73" class="link-to-prism">src/app/ngx-editor/common/services/command-executor.service.ts:73</a></div>
<div class="io-line">Defined in <a href="" data-line="70" class="link-to-prism">src/app/ngx-editor/common/services/command-executor.service.ts:70</a></div>
</td>
</tr>

Expand Down Expand Up @@ -1050,7 +1034,7 @@ <h3 id="inputs">
</tr>
<tr>
<td class="col-md-4">
<div class="io-line">Defined in <a href="" data-line="11" class="link-to-prism">src/app/ngx-editor/common/services/command-executor.service.ts:11</a></div>
<div class="io-line">Defined in <a href="" data-line="9" class="link-to-prism">src/app/ngx-editor/common/services/command-executor.service.ts:9</a></div>
</td>
</tr>

Expand All @@ -1071,9 +1055,7 @@ <h3 id="inputs">
<div class="tab-pane fade tab-source-code" id="c-source">
<pre class="line-numbers compodoc-sourcecode"><code class="language-typescript">import { Injectable } from &#x27;@angular/core&#x27;;
import { HttpClient, HttpRequest } from &#x27;@angular/common/http&#x27;;
import { MessageService } from &#x27;./message.service&#x27;;
import * as Utils from &#x27;../utils/ngx-editor.utils&#x27;;
import { map, tap, last, catchError } from &#x27;rxjs/operators&#x27;;

@Injectable()
export class CommandExecutorService {
Expand All @@ -1084,9 +1066,8 @@ <h3 id="inputs">
/**
*
* @param _http HTTP Client for making http requests
* @param _messageService Message service sends message to the editor
*/
constructor(private _http: HttpClient, private _messageService: MessageService) { }
constructor(private _http: HttpClient) { }

/**
* executes command from the toolbar
Expand Down
4 changes: 2 additions & 2 deletions docs/js/search/search_index.js

Large diffs are not rendered by default.

17 changes: 10 additions & 7 deletions src/app/ngx-editor/ngx-editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export class NgxEditorComponent implements OnInit, ControlValueAccessor {

if (typeof this.onChange === 'function') {
this.onChange(html);
this.monitorEditor(html);
this.togglePlaceholder(html);
}

return;
Expand Down Expand Up @@ -198,10 +198,11 @@ export class NgxEditorComponent implements OnInit, ControlValueAccessor {
* @param value value to be executed when there is a change in contenteditable
*/
writeValue(value: any): void {
this.monitorEditor(value);

if (value === null || value === undefined || value === '') {
return;
this.togglePlaceholder(value);

if (value === null || value === undefined || value === '' || value === '<br>') {
value = null;
}

this.refreshView(value);
Expand Down Expand Up @@ -233,7 +234,7 @@ export class NgxEditorComponent implements OnInit, ControlValueAccessor {
* @param value html string from the editor
*/
refreshView(value: string): void {
const normalizedValue = value == null ? '' : value;
const normalizedValue = value === null ? '' : value;
this._renderer.setProperty(this.textArea.nativeElement, 'innerHTML', normalizedValue);
return;
}
Expand Down Expand Up @@ -268,9 +269,11 @@ export class NgxEditorComponent implements OnInit, ControlValueAccessor {
}

/**
* monitor text area changes
* toggles placeholder based on input string
*
* @param value A HTML string from the editor
*/
monitorEditor(value: any): void {
togglePlaceholder(value: any): void {
if (!value || value === '<br>' || value === '') {
this._renderer.addClass(this.ngxWrapper.nativeElement, 'show-placeholder');
} else {
Expand Down

0 comments on commit 36133e1

Please sign in to comment.