Skip to content

Commit fb2d065

Browse files
Merge pull request #2818 from shubhamkumar9199/feat/replace-ckeditor-with-tinymce-fix
WEB-310-feat(editor): replace CKEditor5 with TinyMCE
2 parents a8f42e4 + 534d2e0 commit fb2d065

File tree

7 files changed

+82
-475
lines changed

7 files changed

+82
-475
lines changed

angular.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@
3434
"src/favicon.ico",
3535
"src/robots.txt",
3636
"src/manifest.json",
37-
"src/assets"
37+
"src/assets",
38+
{
39+
"glob": "**/*",
40+
"input": "node_modules/tinymce",
41+
"output": "assets/tinymce"
42+
}
3843
],
3944
"styles": [
4045
"node_modules/@fortawesome/fontawesome-free/css/all.css",
@@ -49,7 +54,7 @@
4954
"scripts": [],
5055
"allowedCommonJsDependencies": [
5156
"lodash",
52-
"@ckeditor/ckeditor5-build-classic",
57+
"tinymce",
5358
"moment"
5459
],
5560
"browser": "src/main.ts",

package-lock.json

Lines changed: 29 additions & 427 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@
4343
"@angular/platform-browser": "19.2.14",
4444
"@angular/platform-browser-dynamic": "19.2.14",
4545
"@angular/router": "19.2.14",
46-
"@ckeditor/ckeditor5-angular": "6.0.1",
47-
"@ckeditor/ckeditor5-build-classic": "40.2.0",
4846
"@fortawesome/angular-fontawesome": "^1.0.0",
4947
"@fortawesome/fontawesome-free": "^6.7.2",
5048
"@fortawesome/fontawesome-svg-core": "6.2.1",
@@ -54,6 +52,7 @@
5452
"@ngx-translate/http-loader": "^16.0.1",
5553
"@swimlane/ngx-graph": "^10.0.0",
5654
"@tailwindcss/forms": "^0.5.4",
55+
"@tinymce/tinymce-angular": "^9.1.1",
5756
"chart.js": "^4.5.1",
5857
"d3": "^7.9.0",
5958
"exceljs": "^4.4.0",
@@ -64,6 +63,7 @@
6463
"moment": "^2.29.4",
6564
"ngx-mat-select-search": "^7.0.10",
6665
"rxjs": "7.8.1",
66+
"tinymce": "^8.2.2",
6767
"tslib": "^2.0.0",
6868
"vkbeautify": "^0.99.3",
6969
"zone.js": "0.15.1"

src/app/templates/create-edit-template/create-edit-template.component.html

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,17 @@
8181

8282
<mat-card-content>
8383
<div role="editor" class="editor-wrapper">
84-
<label for="ckeditor" class="required-label required-label-ckeditor">
84+
<label for="template-text-editor" class="required-label required-label-editor">
8585
{{ 'labels.inputs.Text' | translate }} <span class="required-asterisk">*</span>
8686
</label>
87-
<ckeditor
88-
#ckEditor
89-
[editor]="Editor"
90-
(change)="onEditorChange($event)"
91-
[data]="templateData.template?.text"
92-
></ckeditor>
87+
<editor
88+
id="template-text-editor"
89+
#tinymceEditor
90+
[init]="tinymceConfig"
91+
[initialValue]="templateData.template?.text || ''"
92+
licenseKey="gpl"
93+
[formControl]="templateForm.controls.text"
94+
></editor>
9395
</div>
9496
</mat-card-content>
9597

src/app/templates/create-edit-template/create-edit-template.component.ts

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,13 @@ import {
99
} from '@angular/forms';
1010
import { Router, ActivatedRoute, RouterLink } from '@angular/router';
1111

12-
/** CKEditor5 Imports */
13-
import ClassicEditor from '@ckeditor/ckeditor5-build-classic';
14-
1512
/** Custom Imports */
1613
import { clientParameterLabels, loanParameterLabels, repaymentParameterLabels } from '../template-parameter-labels';
1714

1815
/** Custom Services */
1916
import { TemplatesService } from '../templates.service';
2017
import { FaIconComponent } from '@fortawesome/angular-fontawesome';
21-
import { CKEditorModule } from '@ckeditor/ckeditor5-angular';
18+
import { EditorComponent, EditorModule, TINYMCE_SCRIPT_SRC } from '@tinymce/tinymce-angular';
2219
import {
2320
MatAccordion,
2421
MatExpansionPanel,
@@ -37,18 +34,37 @@ import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
3734
imports: [
3835
...STANDALONE_SHARED_IMPORTS,
3936
FaIconComponent,
40-
CKEditorModule,
37+
EditorModule,
4138
MatAccordion,
4239
MatExpansionPanel,
4340
MatExpansionPanelHeader,
4441
MatExpansionPanelTitle
42+
],
43+
providers: [
44+
{
45+
provide: TINYMCE_SCRIPT_SRC,
46+
useValue: 'assets/tinymce/tinymce.min.js'
47+
}
4548
]
4649
})
4750
export class CreateEditComponent implements OnInit {
48-
/** CKEditor5 */
49-
public Editor = ClassicEditor;
50-
/** CKEditor5 Template Reference */
51-
@ViewChild('ckEditor', { static: true }) ckEditor: any;
51+
/** TinyMCE instance configuration */
52+
tinymceConfig = {
53+
base_url: 'assets/tinymce',
54+
suffix: '.min',
55+
menubar: false,
56+
branding: false,
57+
height: 320,
58+
forced_root_block: false,
59+
statusbar: false,
60+
elementpath: false,
61+
resize: false,
62+
plugins: 'lists link table media codesample',
63+
toolbar:
64+
'undo redo | blocks | bold italic underline | link | numlist bullist outdent indent | alignleft aligncenter alignright alignjustify | table media | removeformat'
65+
};
66+
/** TinyMCE component reference */
67+
@ViewChild('tinymceEditor', { static: false }) tinymceEditor: EditorComponent;
5268

5369
/** Template form. */
5470
templateForm: UntypedFormGroup;
@@ -166,6 +182,7 @@ export class CreateEditComponent implements OnInit {
166182
});
167183
}
168184
this.setEditorContent('');
185+
this.templateForm.get('text').setValue('');
169186
});
170187
if (this.mode === 'create') {
171188
this.templateForm.get('entity').patchValue(0);
@@ -192,44 +209,31 @@ export class CreateEditComponent implements OnInit {
192209
}
193210

194211
/**
195-
* Adds text to CKEditor at cursor position.
212+
* Adds text to the editor at cursor position.
196213
* @param {string} label Template parameter label.
197214
*/
198215
addText(label: string) {
199-
if (this.ckEditor && this.ckEditor.editorInstance) {
200-
this.ckEditor.editorInstance.model.change((writer: any) => {
201-
const insertPosition = this.ckEditor.editorInstance.model.document.selection.getFirstPosition();
202-
writer.insertText(label, insertPosition);
203-
});
204-
}
216+
this.tinymceEditor?.editor?.insertContent(label);
205217
}
206218

207219
/**
208-
* Gets the contents of CKEditor.
220+
* Gets the contents of the editor.
209221
*/
210222
getEditorContent() {
211-
if (this.ckEditor && this.ckEditor.editorInstance) {
212-
return this.ckEditor.editorInstance.getData();
213-
}
214-
return '';
223+
return this.tinymceEditor?.editor?.getContent({ format: 'html' }) || '';
215224
}
216225

217226
/**
218-
* Sets the contents of CKEditor.
227+
* Sets the contents of the editor.
219228
* @param {string} content Editor Content
220229
*/
221230
setEditorContent(content: string) {
222-
if (this.ckEditor && this.ckEditor.editorInstance) {
223-
return this.ckEditor.editorInstance.setData(content);
231+
if (this.tinymceEditor?.editor) {
232+
this.tinymceEditor.editor.setContent(content || '');
224233
}
225234
return '';
226235
}
227236

228-
onEditorChange(event: any) {
229-
const editorContent = event.editor.getData();
230-
this.templateForm.get('text').setValue(editorContent);
231-
}
232-
233237
/**
234238
* Submits a template.
235239
*/

src/app/templates/templates.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { NgModule } from '@angular/core';
33

44
/** Custom Modules */
5-
import { CKEditorModule } from '@ckeditor/ckeditor5-angular';
5+
import { EditorModule } from '@tinymce/tinymce-angular';
66
import { SharedModule } from '../shared/shared.module';
77
import { DirectivesModule } from '../directives/directives.module';
88
import { TemplatesRoutingModule } from './templates-routing.module';
@@ -19,7 +19,7 @@ import { CreateEditComponent } from './create-edit-template/create-edit-template
1919
*/
2020
@NgModule({
2121
imports: [
22-
CKEditorModule,
22+
EditorModule,
2323
SharedModule,
2424
DirectivesModule,
2525
TemplatesRoutingModule,

src/typings.d.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,3 @@ interface Window {
4343
}
4444

4545
declare module 'chart.js';
46-
47-
declare module '@ckeditor/ckeditor5-build-classic' {
48-
const ClassicEditorBuild: any;
49-
50-
export = ClassicEditorBuild;
51-
}

0 commit comments

Comments
 (0)