Skip to content

Commit 303bf04

Browse files
alinelariguetjhosefmarks
authored andcommitted
feat(rich-text): permite inclusão de imagem
Permite incluir imagem por drag drop, seleção ou por url. Fixes DTHFUI-1717
1 parent 23eb81a commit 303bf04

19 files changed

+801
-25
lines changed

projects/ui/src/lib/components/po-field/po-field.module.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { PoMultiselectItemComponent } from './po-multiselect/po-multiselect-item
3333
import { PoMultiselectSearchComponent } from './po-multiselect/po-multiselect-search/po-multiselect-search.component';
3434
import { PoRichTextBodyComponent } from './po-rich-text/po-rich-text-body/po-rich-text-body.component';
3535
import { PoRichTextComponent } from './po-rich-text/po-rich-text.component';
36+
import { PoRichTextModalComponent } from './po-rich-text/po-rich-text-modal/po-rich-text-modal.component';
3637
import { PoRichTextToolbarComponent } from './po-rich-text/po-rich-text-toolbar/po-rich-text-toolbar.component';
3738
import { PoInputComponent } from './po-input/po-input.component';
3839
import { PoNumberComponent } from './po-number/po-number.component';
@@ -122,6 +123,7 @@ import { PoUrlComponent } from './po-url/po-url.component';
122123
PoRadioGroupComponent,
123124
PoRichTextBodyComponent,
124125
PoRichTextComponent,
126+
PoRichTextModalComponent,
125127
PoRichTextToolbarComponent,
126128
PoSelectComponent,
127129
PoSelectOptionTemplateDirective,
@@ -138,7 +140,8 @@ import { PoUrlComponent } from './po-url/po-url.component';
138140
providers: [],
139141
entryComponents: [
140142
PoCalendarComponent,
141-
PoLookupModalComponent
143+
PoLookupModalComponent,
144+
PoRichTextModalComponent
142145
]
143146
})
144147
export class PoFieldModule { }
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @docsPrivate
3+
*
4+
* @usedBy PoRichTextComponent
5+
*
6+
* @description
7+
*
8+
* *Enum* `PoRichTextModalType` para especificação dos tipos de modal.
9+
*/
10+
export enum PoRichTextModalType {
11+
12+
/**
13+
* Exibe os dados para inserção de imagens.
14+
*/
15+
Image = 'image'
16+
17+
}

projects/ui/src/lib/components/po-field/po-rich-text/po-rich-text-body/po-rich-text-body.component.spec.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,30 @@ describe('PoRichTextBodyComponent:', () => {
114114
expect(component['emitSelectionCommands']).toHaveBeenCalled();
115115
});
116116

117-
it('onKeyUp: should call `updateModel`', () => {
118-
const element = document.createElement('div');
117+
it('onKeyUp: should remove tag `br`', () => {
118+
const element = document.createElement('br');
119119
element.classList.add('teste');
120120
component.bodyElement.nativeElement.appendChild(element);
121121
component.onKeyUp();
122122
expect(nativeElement.querySelector('.teste')).toBeFalsy();
123123
});
124124

125+
it('onKeyUp: should`t remove tag `br`', () => {
126+
const div = document.createElement('div');
127+
const br = document.createElement('br');
128+
129+
br.classList.add('teste-br');
130+
div.classList.add('teste-div');
131+
132+
component.bodyElement.nativeElement.appendChild(div);
133+
component.bodyElement.nativeElement.appendChild(br);
134+
135+
component.onKeyUp();
136+
137+
expect(nativeElement.querySelector('.teste-br')).toBeTruthy();
138+
expect(nativeElement.querySelector('.teste-div')).toBeTruthy();
139+
});
140+
125141
it('onKeyUp: should call `updateModel`', () => {
126142
spyOn(component, <any>'updateModel');
127143
component.onKeyUp();

projects/ui/src/lib/components/po-field/po-rich-text/po-rich-text-body/po-rich-text-body.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ export class PoRichTextBodyComponent implements OnInit {
7474
// Tratamento necessário para eliminar a tag <br> criada no firefox quando o body for limpo.
7575
const bodyElement = this.bodyElement.nativeElement;
7676

77-
if (!bodyElement.innerText.trim() && bodyElement.firstChild) {
78-
bodyElement.firstChild.remove();
77+
if (!bodyElement.innerText.trim() && bodyElement.childNodes.length === 1 && bodyElement.querySelector('br')) {
78+
bodyElement.querySelector('br').remove();
7979
}
8080

8181
this.updateModel();

projects/ui/src/lib/components/po-field/po-rich-text/po-rich-text-literals.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ export const poRichTextLiteralsDefault = {
88
right: 'Right',
99
justify: 'Justify',
1010
textColor: 'Text color',
11-
unorderedList: 'Bulleted list'
11+
unorderedList: 'Bulleted list',
12+
cancel: 'Cancel',
13+
insert: 'Insert',
14+
insertImage: 'Insert image',
15+
urlImage: 'URL image'
1216
},
1317
es: {
1418
bold: 'Negrita',
@@ -19,7 +23,11 @@ export const poRichTextLiteralsDefault = {
1923
right: 'Derecha',
2024
justify: 'Justificado',
2125
textColor: 'Color del texto',
22-
unorderedList: 'Lista con viñetas'
26+
unorderedList: 'Lista con viñetas',
27+
cancel: 'Cancelar',
28+
insert: 'Insertar',
29+
insertImage: 'Insertar imagen',
30+
urlImage: 'Imagen URL'
2331
},
2432
pt: {
2533
bold: 'Negrito',
@@ -30,6 +38,10 @@ export const poRichTextLiteralsDefault = {
3038
right: 'Direita',
3139
justify: 'Justificado',
3240
textColor: 'Cor do texto',
33-
unorderedList: 'Lista com marcadores'
41+
unorderedList: 'Lista com marcadores',
42+
cancel: 'Cancelar',
43+
insert: 'Inserir',
44+
insertImage: 'Inserir imagem',
45+
urlImage: 'Imagem em URL'
3446
}
3547
};
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<po-modal #modal
2+
p-hide-close
3+
[p-primary-action]="modalConfirmAction"
4+
[p-secondary-action]="modalCancelAction"
5+
[p-title]="literals.insertImage">
6+
7+
<ng-container *ngIf="modalType === 'image'; then modalImage"></ng-container>
8+
</po-modal>
9+
10+
<ng-template #modalImage>
11+
<form #modalImageForm="ngForm">
12+
<div class="po-row">
13+
<!-- po-upload desabilita o drag drop caso não tenha valor atribuido para a propriedade p-url -->
14+
<po-upload #upload
15+
class="po-md-12"
16+
name="upload"
17+
[(ngModel)]="uploadModel"
18+
p-drag-drop-height="160"
19+
p-hide-restrictions-info
20+
p-hide-send-button
21+
p-url="x"
22+
[p-drag-drop]="!modal.isHidden"
23+
[p-disabled]="isUrlValid"
24+
[p-restrictions]="uploadRestrictions">
25+
</po-upload>
26+
</div>
27+
28+
<div class="po-row">
29+
<po-url
30+
class="po-md-12 po-mt-3"
31+
name="url"
32+
[(ngModel)]="urlImage"
33+
[p-label]="literals.urlImage"
34+
[p-disabled]="isUploadValid">
35+
</po-url>
36+
</div>
37+
</form>
38+
</ng-template>

0 commit comments

Comments
 (0)