-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #390 from ckeditor/watchdog-demo-update
Other: Added catching and emitting errors that happen during editor initialization. Closes #392
- Loading branch information
Showing
9 changed files
with
205 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
30 changes: 30 additions & 0 deletions
30
src/app/initialization-crash/initialization-crash.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<h2>Initialization crash demo</h2> | ||
<h3>Without watchdog</h3> | ||
<ng-container *ngIf="errorOccurred; then errorMessage; else editor"> | ||
|
||
</ng-container> | ||
|
||
<ng-template #editor> | ||
<ckeditor data="Crash demo without watchdog" [config]="config" [editor]="Editor" | ||
(error)="onError($event)"> | ||
</ckeditor> | ||
</ng-template> | ||
|
||
<ng-template #errorMessage> | ||
<p>An error has occurred, please contact us at: [email protected] to resolve the situation.</p> | ||
</ng-template> | ||
|
||
<h3>With watchdog</h3> | ||
<ng-container *ngIf="errorOccurredWatchdog; then errorMessageWatchdog; else editorWatchdog"> | ||
|
||
</ng-container> | ||
|
||
<ng-template #editorWatchdog> | ||
<ckeditor data="Crash demo with watchdog" [config]="config" [editor]="EditorWatchdog" | ||
[watchdog]="watchdog" (error)="onErrorWatchdog($event)"> | ||
</ckeditor> | ||
</ng-template> | ||
|
||
<ng-template #errorMessageWatchdog> | ||
<p>An error has occurred, please contact us at: [email protected] to resolve the situation.</p> | ||
</ng-template> |
64 changes: 64 additions & 0 deletions
64
src/app/initialization-crash/initialization-crash.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { Component, ViewChild } from '@angular/core'; | ||
import { CKEditorComponent } from 'src/ckeditor'; | ||
import AngularEditor from 'ckeditor/build/ckeditor'; | ||
import type { ContextWatchdog } from '@ckeditor/ckeditor5-watchdog'; | ||
|
||
@Component( { | ||
selector: 'app-initialization-crash', | ||
templateUrl: './initialization-crash.component.html', | ||
styleUrls: [ './initialization-crash.component.css' ] | ||
} ) | ||
export class InitializationCrashComponent { | ||
public Editor = AngularEditor; | ||
public EditorWatchdog = AngularEditor; | ||
|
||
@ViewChild( CKEditorComponent ) public ckeditor?: CKEditorComponent; | ||
|
||
public config: any; | ||
public ready = false; | ||
|
||
public errorOccurred = false; | ||
public errorOccurredWatchdog = false; | ||
|
||
public watchdog?: ContextWatchdog; | ||
|
||
public ngOnInit(): void { | ||
const contextConfig: any = { | ||
foo: 'bar' | ||
}; | ||
|
||
this.config = { | ||
extraPlugins: [ | ||
function( editor: any ) { | ||
editor.data.on( 'init', () => { | ||
// Simulate an error. | ||
// Create a non-existing position, then try to get its parent. | ||
const position = editor.model.createPositionFromPath( editor.model.document.getRoot(), [ 1, 2, 3 ] ); | ||
|
||
return position.parent; | ||
} ); | ||
} | ||
], | ||
collaboration: { | ||
channelId: 'foobar-baz' | ||
} | ||
}; | ||
|
||
this.watchdog = new AngularEditor.ContextWatchdog( AngularEditor.Context ); | ||
|
||
this.watchdog.create( contextConfig ) | ||
.then( () => { | ||
this.ready = true; | ||
} ); | ||
} | ||
|
||
public onError( error: any ): void { | ||
console.error( 'Editor without watchdog threw an error which was caught', error ); | ||
this.errorOccurred = true; | ||
} | ||
|
||
public onErrorWatchdog( error: any ): void { | ||
console.error( 'Editor with watchdog threw an error which was caught', error ); | ||
this.errorOccurredWatchdog = true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,18 @@ | ||
<h2>Watchdog demo</h2> | ||
|
||
<button (click)="toggle()">Toggle disabled mode</button> | ||
<ng-container *ngIf="errorOccurred; then errorMessage; else editor"> | ||
|
||
<ckeditor data="Watchdog demo" [config]="config" [editor]="Editor" (ready)="onReady($event)" [watchdog]="watchdog" | ||
[disabled]="isDisabled"> | ||
</ckeditor> | ||
</ng-container> | ||
|
||
<ng-template #editor> | ||
<p>Type '1' or '2' to crash the editor.</p> | ||
<button (click)="toggle()">Toggle disabled mode</button> | ||
|
||
<ckeditor data="Watchdog demo" [config]="config" [editor]="Editor" (ready)="onReady($event)" [watchdog]="watchdog" | ||
[disabled]="isDisabled" (error)="onError()"> | ||
</ckeditor> | ||
</ng-template> | ||
|
||
<ng-template #errorMessage> | ||
<p>An error has occurred, please contast us at: [email protected] to resolve the situation.</p> | ||
</ng-template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters