Skip to content

Commit 4a410b9

Browse files
FrancescoMolinarovins01-4science
authored andcommitted
Merged in task/ux-plus-2023_02_x/UXP-241-rework (pull request #46)
Task/ux plus 2023 02 x/UXP-241 rework Approved-by: Andrea Barbasso Approved-by: Giuseppe Digilio
2 parents c407f9c + 75dd521 commit 4a410b9

9 files changed

Lines changed: 170 additions & 62 deletions

angular.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@
6969
"inject": false,
7070
"bundleName": "dspace-theme"
7171
},
72-
"./node_modules/leaflet/dist/leaflet.css"
72+
"./node_modules/leaflet/dist/leaflet.css",
73+
"./node_modules/quill/dist/quill.core.css",
74+
"./node_modules/quill/dist/quill.snow.css",
75+
"./node_modules/quill/dist/quill.bubble.css",
76+
"./node_modules/quill-emoji/dist/quill-emoji.css"
7377
],
7478
"scripts": [],
7579
"baseHref": "/"

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@
9191
"@ng-bootstrap/ng-bootstrap": "^11.0.0",
9292
"@ng-dynamic-forms/core": "^15.0.0",
9393
"@ng-dynamic-forms/ui-ng-bootstrap": "^15.0.0",
94-
"@ng-util/markdown": "^12.1.2",
9594
"@ngrx/effects": "^15.4.0",
9695
"@ngrx/router-store": "^15.4.0",
9796
"@ngrx/store": "^15.4.0",
@@ -150,7 +149,10 @@
150149
"ngx-skeleton-loader": "^7.0.0",
151150
"nouislider": "^15.8.1",
152151
"pem": "1.14.8",
152+
"ngx-quill": "21.0.2",
153153
"prop-types": "^15.8.1",
154+
"quill": "1.3.7",
155+
"quill-emoji": "^0.2.0",
154156
"react-copy-to-clipboard": "^5.1.0",
155157
"reflect-metadata": "^0.2.2",
156158
"rxjs": "^7.8.0",

src/app/app.module.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import { APP_CONFIG, AppConfig } from '../config/app-config.interface';
3131
import { StoreDevModules } from '../config/store/devtools';
3232
import { RootModule } from './root.module';
3333
import { DspaceRestInterceptor } from './core/dspace-rest/dspace-rest.interceptor';
34-
import { NuMarkdownModule } from '@ng-util/markdown';
3534
import { FooterModule } from './footer/footer.module';
3635
import { SocialModule } from './social/social.module';
3736
import { DirectivesModule } from './directives/directives.module';
@@ -57,7 +56,6 @@ const IMPORTS = [
5756
FooterModule,
5857
HttpClientModule,
5958
AppRoutingModule,
60-
NuMarkdownModule.forRoot({}),
6159
CoreModule.forRoot(),
6260
ScrollToModule.forRoot(),
6361
NgbModule,
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
<nu-markdown [id]="controlId" [(ngModel)]="editValue" class="markdown-editor"
2-
(ngModelChange)="editValueChange.emit($event)" [options]="options">
3-
</nu-markdown>
1+
<quill-editor class="markdown-editor" [ngModel]="editValue" [modules]="modules" (onContentChanged)="updateContent($event)"></quill-editor>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
quill-editor {
2+
width: 100%;
3+
}

src/app/shared/markdown-editor/markdown-editor.component.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
22
import { NO_ERRORS_SCHEMA } from '@angular/core';
33
import { RouterTestingModule } from '@angular/router/testing';
44

5-
import { By } from '@angular/platform-browser';
5+
import { By, DomSanitizer } from '@angular/platform-browser';
66

77
import { MarkdownEditorComponent } from './markdown-editor.component';
88

@@ -16,7 +16,7 @@ describe('MarkdownEditorComponent', () => {
1616
imports: [
1717
RouterTestingModule.withRoutes([]),
1818
],
19-
providers: [],
19+
providers: [DomSanitizer],
2020
schemas: [NO_ERRORS_SCHEMA]
2121
}).compileComponents();
2222
}));
Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,55 @@
1-
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
1+
import 'quill-emoji/dist/quill-emoji.js';
2+
import { Component, EventEmitter, Input, Output, SecurityContext } from '@angular/core';
3+
import { ContentChange, QuillModules } from 'ngx-quill';
4+
import { DomSanitizer } from '@angular/platform-browser';
25

36
@Component({
47
selector: 'ds-markdown-editor',
58
templateUrl: './markdown-editor.component.html',
69
styleUrls: ['./markdown-editor.component.scss']
710
})
8-
export class MarkdownEditorComponent implements OnInit {
9-
// to allow multiple textarea on the same screen, need to set an uniqueId for the textarea
10-
controlId: string;
11+
export class MarkdownEditorComponent {
1112
/**
1213
* Markdown Editor String value
1314
*/
14-
@Input() editValue: string;
15+
@Input() editValue = '';
1516
/**
1617
* Markdown Editor String value Emitter
1718
*/
1819
@Output() editValueChange = new EventEmitter();
20+
1921
/**
20-
* Nu markdown library options (default is chinese)
22+
* Quill modules config
2123
*/
22-
options = {
23-
minHeight: 200,
24-
lang: 'en_US',
25-
mode: 'ir',
26-
preview: {
27-
markdown: {
28-
codeBlockPreview: false,
29-
},
30-
actions: [
31-
'desktop', 'tablet', 'mobile'
32-
]
24+
modules: QuillModules = {
25+
'emoji-toolbar': true,
26+
toolbar: {
27+
container: [
28+
['bold', 'italic', 'underline', 'strike'],
29+
[{ 'header': 1 }, { 'header': 2 }],
30+
[{ 'list': 'ordered'}, { 'list': 'bullet' }],
31+
[{ 'indent': '-1'}, { 'indent': '+1' }],
32+
[{ 'direction': 'rtl' }],
33+
[{ 'size': ['small', false, 'large', 'huge'] }],
34+
[{ 'header': [1, 2, 3, 4, 5, 6, false] }],
35+
[{ 'font': [] }],
36+
[{ 'align': [] }],
37+
['clean'],
38+
['emoji'],
39+
],
3340
},
34-
toolbar: [
35-
'emoji', 'headings', 'bold', 'italic', 'strike', 'link', '|',
36-
'list', 'ordered-list', 'check', 'outdent', 'indent', 'table', '|',
37-
'quote', 'line', 'code', 'inline-code', 'insert-before', 'insert-after', '|',
38-
'undo', 'redo', '|',
39-
'fullscreen', 'preview'
40-
],
41+
syntax: false
4142
};
4243

43-
ngOnInit(): void {
44-
this.controlId = `MarkdownEditor-${Math.floor(100000 * Math.random())}`;
45-
}
44+
constructor(private sanitizer: DomSanitizer) {}
45+
4646

47+
/**
48+
* Emit content update after editing
49+
* @param content
50+
*/
51+
updateContent(content: ContentChange) {
52+
const sanitizedContent = this.sanitizer.sanitize(SecurityContext.HTML, content.html);
53+
this.editValueChange.emit(sanitizedContent);
54+
}
4755
}

src/app/shared/markdown-editor/markdown-editor.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
22
import { CommonModule } from '@angular/common';
33
import { MarkdownEditorComponent } from './markdown-editor.component';
44
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
5-
import { NuMarkdownModule } from '@ng-util/markdown';
5+
import { QuillModule } from 'ngx-quill';
66

77
@NgModule({
88
imports: [
99
CommonModule,
1010
FormsModule,
1111
ReactiveFormsModule,
12-
NuMarkdownModule
12+
QuillModule
1313
],
1414
exports: [ MarkdownEditorComponent ],
1515
declarations: [ MarkdownEditorComponent ],

0 commit comments

Comments
 (0)