AAE-22612 Fix Rich Text color picker (#9688)

* AAE-22612 Fix Rich Text color picker

* remove readOnly input from editor
This commit is contained in:
Tomasz Gnyp 2024-05-21 09:06:28 +02:00 committed by GitHub
parent 7b6684b0ec
commit 015a4e3cc6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 41 additions and 79 deletions

View File

@ -1,3 +1,3 @@
<div class="adf-rich-text-editor-container"> <div class="adf-rich-text-editor-container">
<div class="editorjs" [ngClass]="{'readonly': readOnly}" id="{{dynamicId}}"></div> <div class="editorjs" id="{{dynamicId}}"></div>
</div> </div>

View File

@ -9,3 +9,9 @@
} }
} }
} }
xy-color-picker {
background-color: transparent;
margin-left: 150px;
width: 22px;
}

View File

@ -105,20 +105,4 @@ describe('RichTextEditorComponent', () => {
expect(destroyEditorSpy).not.toHaveBeenCalled(); expect(destroyEditorSpy).not.toHaveBeenCalled();
}); });
it('should add readonly class if readOnly is set to true', async () => {
component.readOnly = true;
await whenEditorIsReady();
const editorEl = debugElement.query(By.css(cssSelectors.editorJsElement));
expect(editorEl.nativeElement.classList).toContain('readonly');
});
it('should not add readonly class if readOnly is set to false', async () => {
component.readOnly = false;
await whenEditorIsReady();
const editorEl = debugElement.query(By.css(cssSelectors.editorJsElement));
expect(editorEl.nativeElement.classList).not.toContain('readonly');
});
}); });

View File

@ -19,7 +19,6 @@ import { RichTextEditorModule } from './rich-text-editor.module';
import { Meta, moduleMetadata, Story } from '@storybook/angular'; import { Meta, moduleMetadata, Story } from '@storybook/angular';
import { ProcessServicesCloudStoryModule } from '../testing/process-services-cloud-story.module'; import { ProcessServicesCloudStoryModule } from '../testing/process-services-cloud-story.module';
import { RichTextEditorComponent } from './rich-text-editor.component'; import { RichTextEditorComponent } from './rich-text-editor.component';
import { exampleData } from './mocks/rich-text-editor.mock';
export default { export default {
component: RichTextEditorComponent, component: RichTextEditorComponent,
@ -36,14 +35,6 @@ export default {
table: { table: {
type: { summary: 'OutputData' } type: { summary: 'OutputData' }
} }
},
readOnly: {
control: 'boolean',
defaultValue: false,
table: {
type: { summary: 'boolean' },
defaultValue: { summary: 'false' }
}
} }
} }
} as Meta; } as Meta;
@ -51,10 +42,7 @@ export default {
const template: Story<RichTextEditorComponent> = (args: RichTextEditorComponent) => ({ const template: Story<RichTextEditorComponent> = (args: RichTextEditorComponent) => ({
props: args, props: args,
template: ` template: `
<adf-cloud-rich-text-editor <adf-cloud-rich-text-editor [data]=data #editor>
[data]=data
[readOnly]=readOnly
#editor >
</adf-cloud-rich-text-editor> </adf-cloud-rich-text-editor>
<hr/> <hr/>
<h3>Output data from editor:</h3> <h3>Output data from editor:</h3>
@ -90,9 +78,3 @@ defaultRichTextEditor.args = {
version: '2.29.0' version: '2.29.0'
} }
}; };
export const readOnlyRichTextEditor = template.bind({});
readOnlyRichTextEditor.args = {
readOnly: true,
data: exampleData
};

View File

@ -28,13 +28,9 @@ import { editorJsConfig } from './editorjs-config';
encapsulation: ViewEncapsulation.None encapsulation: ViewEncapsulation.None
}) })
export class RichTextEditorComponent implements OnInit, OnDestroy, AfterViewInit { export class RichTextEditorComponent implements OnInit, OnDestroy, AfterViewInit {
@Input() @Input()
data: OutputData; data: OutputData;
@Input()
readOnly = false;
private _outputData = new Subject<OutputData>(); private _outputData = new Subject<OutputData>();
outputData$ = this._outputData.asObservable(); outputData$ = this._outputData.asObservable();
@ -43,9 +39,6 @@ export class RichTextEditorComponent implements OnInit, OnDestroy, AfterViewInit
dynamicId: string; dynamicId: string;
isReady = false; isReady = false;
constructor() {
}
ngOnInit(): void { ngOnInit(): void {
this.dynamicId = `editorjs-${crypto.getRandomValues(new Uint32Array(1))}`; this.dynamicId = `editorjs-${crypto.getRandomValues(new Uint32Array(1))}`;
} }
@ -55,25 +48,23 @@ export class RichTextEditorComponent implements OnInit, OnDestroy, AfterViewInit
holder: this.dynamicId, holder: this.dynamicId,
...editorJsConfig, ...editorJsConfig,
data: this.data, data: this.data,
readOnly: this.readOnly,
onChange: () => { onChange: () => {
if (!this.readOnly) {
this.sendEditorOutputData(); this.sendEditorOutputData();
}
}, },
onReady: () => { onReady: () => {
this.isReady = true; this.isReady = true;
if (!this.readOnly) {
this.sendEditorOutputData(); this.sendEditorOutputData();
} }
}
} as any); } as any);
} }
private sendEditorOutputData() { private sendEditorOutputData() {
this.editorInstance.save().then((outputData) => { this.editorInstance
.save()
.then((outputData) => {
this._outputData.next(outputData); this._outputData.next(outputData);
}).catch((error) => { })
.catch((error) => {
console.error('Saving failed: ', error); console.error('Saving failed: ', error);
}); });
} }
@ -87,5 +78,4 @@ export class RichTextEditorComponent implements OnInit, OnDestroy, AfterViewInit
this.editorInstance.destroy(); this.editorInstance.destroy();
} }
} }
} }

16
package-lock.json generated
View File

@ -56,7 +56,7 @@
"@angular/cli": "~14.2.12", "@angular/cli": "~14.2.12",
"@angular/compiler-cli": "14.1.3", "@angular/compiler-cli": "14.1.3",
"@editorjs/code": "2.9.0", "@editorjs/code": "2.9.0",
"@editorjs/editorjs": "^2.29.0", "@editorjs/editorjs": "^2.28.2",
"@editorjs/header": "2.8.1", "@editorjs/header": "2.8.1",
"@editorjs/inline-code": "1.5.0", "@editorjs/inline-code": "1.5.0",
"@editorjs/list": "1.9.0", "@editorjs/list": "1.9.0",
@ -96,7 +96,7 @@
"dotenv": "16.4.5", "dotenv": "16.4.5",
"editorjs-html": "3.4.3", "editorjs-html": "3.4.3",
"editorjs-paragraph-with-alignment": "3.0.0", "editorjs-paragraph-with-alignment": "3.0.0",
"editorjs-text-color-plugin": "2.0.4", "editorjs-text-color-plugin": "1.13.1",
"ejs": "^3.1.10", "ejs": "^3.1.10",
"eslint": "^8.47.0", "eslint": "^8.47.0",
"eslint-config-prettier": "^8.10.0", "eslint-config-prettier": "^8.10.0",
@ -4502,9 +4502,9 @@
} }
}, },
"node_modules/@editorjs/editorjs": { "node_modules/@editorjs/editorjs": {
"version": "2.29.0", "version": "2.28.2",
"resolved": "https://registry.npmjs.org/@editorjs/editorjs/-/editorjs-2.29.0.tgz", "resolved": "https://registry.npmjs.org/@editorjs/editorjs/-/editorjs-2.28.2.tgz",
"integrity": "sha512-w2BVboSHokMBd/cAOZn0UU328o3gSZ8XUvFPA2e9+ciIGKILiRSPB70kkNdmhHkuNS3q2px+vdaIFaywBl7wGA==", "integrity": "sha512-g6V0Nd3W9IIWMpvxDNTssQ6e4kxBp1Y0W4GIf8cXRlmcBp3TUjrgCYJQmNy3l2a6ZzhyBAoVSe8krJEq4g7PQw==",
"dev": true "dev": true
}, },
"node_modules/@editorjs/header": { "node_modules/@editorjs/header": {
@ -30545,9 +30545,9 @@
"license": "MIT" "license": "MIT"
}, },
"node_modules/editorjs-text-color-plugin": { "node_modules/editorjs-text-color-plugin": {
"version": "2.0.4", "version": "1.13.1",
"resolved": "https://registry.npmjs.org/editorjs-text-color-plugin/-/editorjs-text-color-plugin-2.0.4.tgz", "resolved": "https://registry.npmjs.org/editorjs-text-color-plugin/-/editorjs-text-color-plugin-1.13.1.tgz",
"integrity": "sha512-QpibTkOxs3ndlKNOLT8ZlC4ktc3/eKIajiLO0Jm/hh9AJug/CrM1/rAvHy+ldfUKavbWeI+YZvgjad0YTyoyGw==", "integrity": "sha512-iCK274omDhoU7/zIFwV1fP5ydgfObYXSGV+q2zlFq3D4JDnvtn0KP+6NPM1A4dDlxTczpywPByRKIwmf7z4CIg==",
"dev": true "dev": true
}, },
"node_modules/ee-first": { "node_modules/ee-first": {

View File

@ -101,7 +101,7 @@
"@angular/cli": "~14.2.12", "@angular/cli": "~14.2.12",
"@angular/compiler-cli": "14.1.3", "@angular/compiler-cli": "14.1.3",
"@editorjs/code": "2.9.0", "@editorjs/code": "2.9.0",
"@editorjs/editorjs": "^2.29.0", "@editorjs/editorjs": "^2.28.2",
"@editorjs/header": "2.8.1", "@editorjs/header": "2.8.1",
"@editorjs/inline-code": "1.5.0", "@editorjs/inline-code": "1.5.0",
"@editorjs/list": "1.9.0", "@editorjs/list": "1.9.0",
@ -141,7 +141,7 @@
"dotenv": "16.4.5", "dotenv": "16.4.5",
"editorjs-html": "3.4.3", "editorjs-html": "3.4.3",
"editorjs-paragraph-with-alignment": "3.0.0", "editorjs-paragraph-with-alignment": "3.0.0",
"editorjs-text-color-plugin": "2.0.4", "editorjs-text-color-plugin": "1.13.1",
"ejs": "^3.1.10", "ejs": "^3.1.10",
"eslint": "^8.47.0", "eslint": "^8.47.0",
"eslint-config-prettier": "^8.10.0", "eslint-config-prettier": "^8.10.0",