mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[AAE-12723] Move rich text editor in Process cloud (#8283)
* move rich text editor in Process cloud * fix import * fix * fix
This commit is contained in:
@@ -25,6 +25,7 @@ import { GroupCloudWidgetComponent } from './widgets/group/group-cloud.widget';
|
||||
import { PropertiesViewerWidgetComponent } from './widgets/properties-viewer/properties-viewer.widget';
|
||||
import { RadioButtonsCloudWidgetComponent } from './widgets/radio-buttons/radio-buttons-cloud.widget';
|
||||
import { FileViewerWidgetComponent } from './widgets/file-viewer/file-viewer.widget';
|
||||
import { DisplayRichTextWidgetComponent } from './widgets/display-rich-text/display-rich-text.widget';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -41,7 +42,8 @@ export class CloudFormRenderingService extends FormRenderingService {
|
||||
[FormFieldTypes.FUNCTIONAL_GROUP]: () => GroupCloudWidgetComponent,
|
||||
[FormFieldTypes.PROPERTIES_VIEWER]: () => PropertiesViewerWidgetComponent,
|
||||
[FormFieldTypes.RADIO_BUTTONS]: () => RadioButtonsCloudWidgetComponent,
|
||||
[FormFieldTypes.ALFRESCO_FILE_VIEWER]: () => FileViewerWidgetComponent
|
||||
[FormFieldTypes.ALFRESCO_FILE_VIEWER]: () => FileViewerWidgetComponent,
|
||||
[FormFieldTypes.DISPLAY_RICH_TEXT]: () => DisplayRichTextWidgetComponent
|
||||
}, true);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,3 @@
|
||||
<div class="adf-display-rich-text-widget">
|
||||
<div class="adf-display-rich-text-widget-parsed-html" [innerHTML]="parsedHTML"></div>
|
||||
</div>
|
@@ -0,0 +1,22 @@
|
||||
.adf-display-rich-text-widget {
|
||||
padding: 10px;
|
||||
|
||||
pre {
|
||||
min-height: 100px;
|
||||
font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;
|
||||
color: #41314e;
|
||||
line-height: 1.6em;
|
||||
font-size: 12px;
|
||||
background: #f8f7fa;
|
||||
border: 1px solid #f1f1f4;
|
||||
box-shadow: none;
|
||||
white-space: pre;
|
||||
word-wrap: normal;
|
||||
overflow-x: auto;
|
||||
resize: vertical;
|
||||
border-radius: 3px;
|
||||
padding: 10px 12px;
|
||||
outline: none;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
@@ -0,0 +1,90 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { DebugElement } from '@angular/core';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { CoreTestingModule, setupTestBed } from '@alfresco/adf-core';
|
||||
|
||||
import { DisplayRichTextWidgetComponent } from './display-rich-text.widget';
|
||||
|
||||
describe('DisplayRichTextWidgetComponent', () => {
|
||||
let widget: DisplayRichTextWidgetComponent;
|
||||
let fixture: ComponentFixture<DisplayRichTextWidgetComponent>;
|
||||
let debugEl: DebugElement;
|
||||
|
||||
const cssSelector = {
|
||||
parsedHTML: '.adf-display-rich-text-widget-parsed-html'
|
||||
};
|
||||
|
||||
const fakeFormField: any = {
|
||||
id: 'fake-form-field',
|
||||
name: 'fake-label',
|
||||
value: {
|
||||
time: 1658154611110,
|
||||
blocks: [
|
||||
{
|
||||
id: '1',
|
||||
type: 'header',
|
||||
data: {
|
||||
text: 'Editor.js',
|
||||
level: 1
|
||||
}
|
||||
}
|
||||
],
|
||||
version: 1
|
||||
},
|
||||
required: false,
|
||||
readOnly: false,
|
||||
overrideId: false,
|
||||
colspan: 1,
|
||||
placeholder: null,
|
||||
minLength: 0,
|
||||
maxLength: 0,
|
||||
params: {
|
||||
existingColspan: 1,
|
||||
maxColspan: 1
|
||||
}
|
||||
};
|
||||
|
||||
setupTestBed({
|
||||
imports: [
|
||||
CoreTestingModule
|
||||
]
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(DisplayRichTextWidgetComponent);
|
||||
widget = fixture.componentInstance;
|
||||
debugEl = fixture.debugElement;
|
||||
widget.field = fakeFormField;
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
fixture.detectChanges();
|
||||
expect(widget).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should parse editorjs data to html', async () => {
|
||||
const expectedHtml = '<h1>Editor.js</h1>';
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
const parsedHtmlEl = debugEl.query(By.css(cssSelector.parsedHTML));
|
||||
expect(parsedHtmlEl.nativeElement.innerHTML).toEqual(expectedHtml);
|
||||
});
|
||||
|
||||
});
|
@@ -0,0 +1,54 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/* eslint-disable @angular-eslint/component-selector */
|
||||
|
||||
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
|
||||
import { WidgetComponent, FormService } from '@alfresco/adf-core';
|
||||
/* cspell:disable-next-line */
|
||||
import edjsHTML from 'editorjs-html';
|
||||
@Component({
|
||||
selector: 'display-rich-text',
|
||||
templateUrl: './display-rich-text.widget.html',
|
||||
styleUrls: ['./display-rich-text.widget.scss'],
|
||||
host: {
|
||||
'(click)': 'event($event)',
|
||||
'(blur)': 'event($event)',
|
||||
'(change)': 'event($event)',
|
||||
'(focus)': 'event($event)',
|
||||
'(focusin)': 'event($event)',
|
||||
'(focusout)': 'event($event)',
|
||||
'(input)': 'event($event)',
|
||||
'(invalid)': 'event($event)',
|
||||
'(select)': 'event($event)'
|
||||
},
|
||||
encapsulation: ViewEncapsulation.None
|
||||
})
|
||||
export class DisplayRichTextWidgetComponent extends WidgetComponent implements OnInit {
|
||||
|
||||
parsedHTML: any;
|
||||
|
||||
constructor(public formService: FormService) {
|
||||
super(formService);
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
/* cspell:disable-next-line */
|
||||
this.parsedHTML = edjsHTML().parseStrict(this.field.value).join('\n');
|
||||
}
|
||||
|
||||
}
|
@@ -40,6 +40,7 @@ import { PropertiesViewerWrapperComponent } from './components/widgets/propertie
|
||||
import { RadioButtonsCloudWidgetComponent } from './components/widgets/radio-buttons/radio-buttons-cloud.widget';
|
||||
import { FilePropertiesTableCloudComponent } from './components/widgets/attach-file/file-properties-table-cloud.component';
|
||||
import { FileViewerWidgetComponent } from './components/widgets/file-viewer/file-viewer.widget';
|
||||
import { RichTextEditorModule } from '../rich-text-editor';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
@@ -54,7 +55,8 @@ import { FileViewerWidgetComponent } from './components/widgets/file-viewer/file
|
||||
GroupCloudModule,
|
||||
ContentMetadataModule,
|
||||
UploadModule,
|
||||
AlfrescoViewerModule
|
||||
AlfrescoViewerModule,
|
||||
RichTextEditorModule
|
||||
],
|
||||
declarations: [
|
||||
FormCloudComponent,
|
||||
|
@@ -35,6 +35,7 @@ import { PeopleCloudModule } from './people/people-cloud.module';
|
||||
import { CloudFormRenderingService } from './form/components/cloud-form-rendering.service';
|
||||
import { ProcessServicesCloudPipeModule } from './pipes/process-services-cloud-pipe.module';
|
||||
import { ApolloModule } from 'apollo-angular';
|
||||
import { RichTextEditorModule } from './rich-text-editor/rich-text-editor.module';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
@@ -47,7 +48,8 @@ import { ApolloModule } from 'apollo-angular';
|
||||
FormCloudModule,
|
||||
TaskFormModule,
|
||||
ProcessServicesCloudPipeModule,
|
||||
ApolloModule
|
||||
ApolloModule,
|
||||
RichTextEditorModule
|
||||
],
|
||||
providers: [
|
||||
{
|
||||
@@ -67,7 +69,8 @@ import { ApolloModule } from 'apollo-angular';
|
||||
FormCloudModule,
|
||||
TaskFormModule,
|
||||
PeopleCloudModule,
|
||||
ProcessServicesCloudPipeModule
|
||||
ProcessServicesCloudPipeModule,
|
||||
RichTextEditorModule
|
||||
]
|
||||
})
|
||||
export class ProcessServicesCloudModule {
|
||||
|
@@ -0,0 +1,72 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/** Plugin import */
|
||||
import CodeTool from '@editorjs/code';
|
||||
import Header from '@editorjs/header';
|
||||
import InlineCode from '@editorjs/inline-code';
|
||||
import List from '@editorjs/list';
|
||||
import Marker from '@editorjs/marker';
|
||||
import Underline from '@editorjs/underline';
|
||||
import ChangeFontSize from '@quanzo/change-font-size';
|
||||
import ColorPlugin from 'editorjs-text-color-plugin';
|
||||
|
||||
export const editorJsConfig = {
|
||||
autofocus: true,
|
||||
logLevel: 'ERROR',
|
||||
tools: {
|
||||
underline: {
|
||||
class: Underline,
|
||||
shortcut: 'CMD+U'
|
||||
},
|
||||
header: {
|
||||
class: Header,
|
||||
inlineToolbar: true
|
||||
},
|
||||
list: {
|
||||
class: List,
|
||||
inlineToolbar: true,
|
||||
config: {
|
||||
defaultStyle: 'unordered'
|
||||
}
|
||||
},
|
||||
Color: {
|
||||
class: ColorPlugin,
|
||||
config: {
|
||||
customPicker: true,
|
||||
colorCollections: ['#FF1300', '#ffa500', '#9C27B0', '#673AB7', '#3F51B5', '#0070FF', '#03A9F4', '#00BCD4', '#5f9ea0', '#4CAF50', '#8BC34A', '#CDDC39', '#FFF', '#000', '#c0c0c0', '#808080', '#800000'],
|
||||
defaultColor: '#FF1300',
|
||||
type: 'text'
|
||||
}
|
||||
},
|
||||
Marker: {
|
||||
class: Marker,
|
||||
shortcut: 'CMD+M'
|
||||
},
|
||||
'Increase/Decrease font size': {
|
||||
class: ChangeFontSize,
|
||||
config: {
|
||||
cssClass: 'plus20pc'
|
||||
}
|
||||
},
|
||||
inlineCode: {
|
||||
class: InlineCode,
|
||||
shortcut: 'CMD+SHIFT+M'
|
||||
},
|
||||
code: CodeTool
|
||||
}
|
||||
};
|
18
lib/process-services-cloud/src/lib/rich-text-editor/index.ts
Normal file
18
lib/process-services-cloud/src/lib/rich-text-editor/index.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export * from './public-api';
|
@@ -0,0 +1,54 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export const exampleData = {
|
||||
time: 1663761278752,
|
||||
blocks: [
|
||||
{
|
||||
id: 'yOV_DfEQhC',
|
||||
type: 'paragraph',
|
||||
data: {
|
||||
text: 'text value'
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'IZwymOWyds',
|
||||
type: 'header',
|
||||
data: {
|
||||
text: 'Heading value',
|
||||
level: 2
|
||||
}
|
||||
},
|
||||
{
|
||||
id: '3JJj6A8XFO',
|
||||
type: 'list',
|
||||
data: {
|
||||
style: 'unordered',
|
||||
items: ['unordered list item A', 'unordered list item B']
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'q98W4eK4Nj',
|
||||
type: 'list',
|
||||
data: {
|
||||
style: 'ordered',
|
||||
items: ['ordered list item 1', 'ordered list item 2']
|
||||
}
|
||||
}
|
||||
],
|
||||
version: '2.25.0'
|
||||
};
|
@@ -0,0 +1,19 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export * from './rich-text-editor.component';
|
||||
export * from './rich-text-editor.module';
|
@@ -0,0 +1,3 @@
|
||||
<div class="adf-rich-text-editor-container">
|
||||
<div class="editorjs" [ngClass]="{'readonly': readOnly}" id="{{dynamicId}}"></div>
|
||||
</div>
|
@@ -0,0 +1,10 @@
|
||||
/* stylelint-disable selector-class-pattern */
|
||||
.adf-rich-text-editor-container {
|
||||
.editorjs {
|
||||
&.readonly {
|
||||
.codex-editor__redactor {
|
||||
padding-bottom: 0 !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,122 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { DebugElement } from '@angular/core';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
|
||||
import { RichTextEditorComponent } from './rich-text-editor.component';
|
||||
|
||||
describe('RichTextEditorComponent', () => {
|
||||
let component: RichTextEditorComponent;
|
||||
let fixture: ComponentFixture<RichTextEditorComponent>;
|
||||
let debugElement: DebugElement;
|
||||
|
||||
const cssSelectors = {
|
||||
editorContent: '.codex-editor',
|
||||
editorJsElement: '.editorjs'
|
||||
};
|
||||
|
||||
const mockEditorData = {
|
||||
time: 1658154611110,
|
||||
blocks: [
|
||||
{
|
||||
id: '1',
|
||||
type: 'header',
|
||||
data: {
|
||||
text: 'Editor.js',
|
||||
level: 2
|
||||
}
|
||||
}
|
||||
],
|
||||
version: 1
|
||||
};
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [RichTextEditorComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(RichTextEditorComponent);
|
||||
component = fixture.componentInstance;
|
||||
debugElement = fixture.debugElement;
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
fixture.detectChanges();
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should render rich text editor', async () => {
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
const editor = debugElement.query(By.css(cssSelectors.editorContent));
|
||||
expect(editor).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should generate dynamic id', async () => {
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
expect(component.dynamicId).toContain('editorjs');
|
||||
});
|
||||
|
||||
it('should get editorjs data by calling getEditorContent', async () => {
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
spyOn(component.editorInstance, 'save').and.returnValue(Promise.resolve(mockEditorData) as any);
|
||||
const savedEditorData = await component.getEditorContent();
|
||||
expect(savedEditorData).toEqual(mockEditorData);
|
||||
});
|
||||
|
||||
it('should destroy editor instance on ngOnDestroy', async () => {
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
const destroyEditorSpy = spyOn(component.editorInstance, 'destroy');
|
||||
component.ngOnDestroy();
|
||||
expect(destroyEditorSpy).toHaveBeenCalledTimes(1);
|
||||
expect(destroyEditorSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not destroy editor instance on ngOnDestroy if editor is not ready', async () => {
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
const destroyEditorSpy = spyOn(component.editorInstance, 'destroy');
|
||||
component.isReady = false;
|
||||
component.ngOnDestroy();
|
||||
expect(destroyEditorSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should add readonly class if readOnly is set to true', async () => {
|
||||
component.readOnly = true;
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
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;
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
const editorEl = debugElement.query(By.css(cssSelectors.editorJsElement));
|
||||
expect(editorEl.nativeElement.classList).not.toContain('readonly');
|
||||
});
|
||||
|
||||
});
|
@@ -0,0 +1,86 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { RichTextEditorModule } from './rich-text-editor.module';
|
||||
import { Meta, moduleMetadata, Story } from '@storybook/angular';
|
||||
import { ProcessServicesCloudStoryModule } from '../testing/process-services-cloud-story.module';
|
||||
import { RichTextEditorComponent } from './rich-text-editor.component';
|
||||
import { exampleData } from './mocks/rich-text-editor.mock';
|
||||
|
||||
export default {
|
||||
component: RichTextEditorComponent,
|
||||
title: 'Core/Rich Text Editor/Rich Text Editor',
|
||||
decorators: [
|
||||
moduleMetadata({
|
||||
imports: [ProcessServicesCloudStoryModule, RichTextEditorModule]
|
||||
})
|
||||
],
|
||||
argTypes: {
|
||||
data: {
|
||||
control: 'object',
|
||||
description: 'Output data.',
|
||||
table: {
|
||||
type: { summary: 'OutputData' }
|
||||
}
|
||||
},
|
||||
readOnly: {
|
||||
control: 'boolean',
|
||||
defaultValue: false,
|
||||
table: {
|
||||
type: { summary: 'boolean' },
|
||||
defaultValue: { summary: 'false' }
|
||||
}
|
||||
}
|
||||
}
|
||||
} as Meta;
|
||||
|
||||
const template: Story<RichTextEditorComponent> = (args: RichTextEditorComponent) => ({
|
||||
props: args,
|
||||
template: `
|
||||
<adf-rich-text-editor
|
||||
[data]=data
|
||||
[readOnly]=readOnly
|
||||
#editor >
|
||||
</adf-rich-text-editor>
|
||||
<hr/>
|
||||
<h3>Output data from editor:</h3>
|
||||
<pre>{{editor.outputData$ | async | json}}</pre>
|
||||
`
|
||||
});
|
||||
|
||||
export const defaultRichTextEditor = template.bind({});
|
||||
defaultRichTextEditor.args = {
|
||||
data: {
|
||||
time: 1663761278752,
|
||||
blocks: [
|
||||
{
|
||||
id: 'yOV_DfEQhC',
|
||||
type: 'paragraph',
|
||||
data: {
|
||||
text: 'text'
|
||||
}
|
||||
}
|
||||
],
|
||||
version: '2.25.0'
|
||||
}
|
||||
};
|
||||
|
||||
export const readOnlyRichTextEditor = template.bind({});
|
||||
readOnlyRichTextEditor.args = {
|
||||
readOnly: true,
|
||||
data: exampleData
|
||||
};
|
@@ -0,0 +1,91 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { AfterViewInit, Component, Input, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core';
|
||||
|
||||
import EditorJS, { OutputData } from '@editorjs/editorjs';
|
||||
import { Subject } from 'rxjs';
|
||||
import { editorJsConfig } from './editorjs-config';
|
||||
|
||||
@Component({
|
||||
selector: 'adf-cloud-rich-text-editor',
|
||||
templateUrl: './rich-text-editor.component.html',
|
||||
styleUrls: ['./rich-text-editor.component.scss'],
|
||||
encapsulation: ViewEncapsulation.None
|
||||
})
|
||||
export class RichTextEditorComponent implements OnInit, OnDestroy, AfterViewInit {
|
||||
|
||||
@Input()
|
||||
data: OutputData;
|
||||
|
||||
@Input()
|
||||
readOnly = false;
|
||||
|
||||
private _outputData = new Subject<OutputData>();
|
||||
|
||||
outputData$ = this._outputData.asObservable();
|
||||
|
||||
editorInstance: EditorJS;
|
||||
dynamicId: string;
|
||||
isReady = false;
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.dynamicId = `editorjs-${crypto.getRandomValues(new Uint32Array(1))}`;
|
||||
}
|
||||
|
||||
ngAfterViewInit(): void {
|
||||
this.editorInstance = new EditorJS({
|
||||
holder: this.dynamicId,
|
||||
...editorJsConfig,
|
||||
data: this.data,
|
||||
readOnly: this.readOnly,
|
||||
onChange: () => {
|
||||
if (!this.readOnly) {
|
||||
this.sendEditorOutputData();
|
||||
}
|
||||
},
|
||||
onReady: () => {
|
||||
this.isReady = true;
|
||||
if (!this.readOnly) {
|
||||
this.sendEditorOutputData();
|
||||
}
|
||||
}
|
||||
} as any);
|
||||
}
|
||||
|
||||
private sendEditorOutputData() {
|
||||
this.editorInstance.save().then((outputData) => {
|
||||
this._outputData.next(outputData);
|
||||
}).catch((error) => {
|
||||
console.error('Saving failed: ', error);
|
||||
});
|
||||
}
|
||||
|
||||
getEditorContent() {
|
||||
return this.editorInstance.save();
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
if (this.isReady) {
|
||||
this.editorInstance.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { RichTextEditorComponent } from './rich-text-editor.component';
|
||||
|
||||
|
||||
@NgModule({
|
||||
declarations: [RichTextEditorComponent],
|
||||
imports: [
|
||||
CommonModule
|
||||
],
|
||||
exports: [RichTextEditorComponent]
|
||||
})
|
||||
export class RichTextEditorModule { }
|
@@ -23,6 +23,8 @@ export * from './lib/group/public-api';
|
||||
export * from './lib/people/public-api';
|
||||
export * from './lib/form/public-api';
|
||||
export * from './lib/services/public-api';
|
||||
export * from './lib/rich-text-editor/public-api';
|
||||
|
||||
export * from './lib/types';
|
||||
export * from './lib/pipes/process-name-cloud.pipe';
|
||||
export * from './lib/pipes/process-services-cloud-pipe.module';
|
||||
|
Reference in New Issue
Block a user