Browse Source

Fix tiny MCE Problem in arrays.

pull/431/head
Sebastian Stehle 6 years ago
parent
commit
e4e6aa5346
  1. 2
      src/Squidex/app/features/content/shared/array-editor.component.html
  2. 10
      src/Squidex/app/features/content/shared/array-editor.component.ts
  3. 13
      src/Squidex/app/features/content/shared/array-item.component.ts
  4. 2
      src/Squidex/app/features/content/shared/field-editor.component.html
  5. 18
      src/Squidex/app/features/content/shared/field-editor.component.ts
  6. 2
      src/Squidex/app/shared/components/rich-editor.component.html
  7. 8
      src/Squidex/app/shared/components/rich-editor.component.scss
  8. 13
      src/Squidex/app/shared/components/rich-editor.component.ts

2
src/Squidex/app/features/content/shared/array-editor.component.html

@ -3,7 +3,7 @@
[cdkDropListDisabled]="false" [cdkDropListDisabled]="false"
[cdkDropListData]="arrayControl.controls" [cdkDropListData]="arrayControl.controls"
(cdkDropListDropped)="sort($event)"> (cdkDropListDropped)="sort($event)">
<div *ngFor="let itemForm of arrayControl.controls; let i = index; trackBy:trackByControl" <div *ngFor="let itemForm of arrayControl.controls; let i = index;"
class="table-drag item" class="table-drag item"
cdkDrag cdkDrag
cdkDragLockAxis="y"> cdkDragLockAxis="y">

10
src/Squidex/app/features/content/shared/array-editor.component.ts

@ -70,6 +70,12 @@ export class ArrayEditorComponent {
}); });
} }
private reset() {
this.children.forEach(component => {
component.reset();
});
}
public move(control: AbstractControl, index: number) { public move(control: AbstractControl, index: number) {
let controls = [...this.arrayControl.controls]; let controls = [...this.arrayControl.controls];
@ -83,9 +89,7 @@ export class ArrayEditorComponent {
for (let i = 0; i < controls.length; i++) { for (let i = 0; i < controls.length; i++) {
this.arrayControl.setControl(i, controls[i]); this.arrayControl.setControl(i, controls[i]);
} }
}
public trackByControl(index: number, control: AbstractControl) { this.reset();
return control;
} }
} }

13
src/Squidex/app/features/content/shared/array-item.component.ts

@ -5,7 +5,7 @@
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. * Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
*/ */
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, Input, OnChanges, OnDestroy, Output, SimpleChanges } from '@angular/core'; import { ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, Input, OnChanges, OnDestroy, Output, QueryList, SimpleChanges, ViewChildren } from '@angular/core';
import { AbstractControl, FormGroup } from '@angular/forms'; import { AbstractControl, FormGroup } from '@angular/forms';
import { Observable, Subscription } from 'rxjs'; import { Observable, Subscription } from 'rxjs';
import { startWith } from 'rxjs/operators'; import { startWith } from 'rxjs/operators';
@ -19,6 +19,8 @@ import {
RootFieldDto RootFieldDto
} from '@app/shared'; } from '@app/shared';
import { FieldEditorComponent } from './field-editor.component';
type FieldControl = { field: FieldDto, control: AbstractControl }; type FieldControl = { field: FieldDto, control: AbstractControl };
@Component({ @Component({
@ -69,6 +71,9 @@ export class ArrayItemComponent implements OnChanges, OnDestroy {
@Input() @Input()
public languages: ReadonlyArray<AppLanguageDto>; public languages: ReadonlyArray<AppLanguageDto>;
@ViewChildren(FieldEditorComponent)
public editors: QueryList<FieldEditorComponent>;
public isHidden = false; public isHidden = false;
public isInvalid: Observable<boolean>; public isInvalid: Observable<boolean>;
@ -174,6 +179,12 @@ export class ArrayItemComponent implements OnChanges, OnDestroy {
this.move.emit(99999); this.move.emit(99999);
} }
public reset() {
this.editors.forEach(editor => {
editor.reset();
});
}
public trackByField(index: number, control: FieldControl) { public trackByField(index: number, control: FieldControl) {
return control.field.name; return control.field.name;
} }

2
src/Squidex/app/features/content/shared/field-editor.component.html

@ -109,7 +109,7 @@
<textarea class="form-control" [formControl]="editorControl" rows="5" [placeholder]="field.displayPlaceholder"></textarea> <textarea class="form-control" [formControl]="editorControl" rows="5" [placeholder]="field.displayPlaceholder"></textarea>
</ng-container> </ng-container>
<ng-container *ngSwitchCase="'RichText'"> <ng-container *ngSwitchCase="'RichText'">
<sqx-rich-editor [formControl]="editorControl"></sqx-rich-editor> <sqx-rich-editor [formControl]="editorControl" #editor></sqx-rich-editor>
</ng-container> </ng-container>
<ng-container *ngSwitchCase="'Html'"> <ng-container *ngSwitchCase="'Html'">
<sqx-code-editor height="350" [formControl]="editorControl" mode="ace/mode/html"></sqx-code-editor> <sqx-code-editor height="350" [formControl]="editorControl" mode="ace/mode/html"></sqx-code-editor>

18
src/Squidex/app/features/content/shared/field-editor.component.ts

@ -5,7 +5,7 @@
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. * Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
*/ */
import { Component, Input } from '@angular/core'; import { Component, ElementRef, Input, ViewChild } from '@angular/core';
import { AbstractControl, FormArray, FormControl } from '@angular/forms'; import { AbstractControl, FormArray, FormControl } from '@angular/forms';
import { import {
@ -13,7 +13,8 @@ import {
EditContentForm, EditContentForm,
FieldDto, FieldDto,
MathHelper, MathHelper,
RootFieldDto RootFieldDto,
Types
} from '@app/shared'; } from '@app/shared';
@Component({ @Component({
@ -46,6 +47,9 @@ export class FieldEditorComponent {
@Input() @Input()
public displaySuffix: string; public displaySuffix: string;
@ViewChild('editor', { static: false })
public editor: ElementRef;
public get arrayControl() { public get arrayControl() {
return this.control as FormArray; return this.control as FormArray;
} }
@ -59,4 +63,14 @@ export class FieldEditorComponent {
} }
public uniqueId = MathHelper.guid(); public uniqueId = MathHelper.guid();
public reset() {
if (this.editor.nativeElement && Types.isFunction(this.editor.nativeElement['reset'])) {
this.editor.nativeElement['reset']();
}
if (this.editor && Types.isFunction(this.editor['reset'])) {
this.editor['reset']();
}
}
} }

2
src/Squidex/app/shared/components/rich-editor.component.html

@ -1,4 +1,4 @@
<div class="drop-container" (sqxDropFile)="insertFiles($event)" [onlyImages]="true"> <div class="drop-container" (sqxDropFile)="insertFiles($event)" [onlyImages]="true" #container>
<div class="editor" #editor></div> <div class="editor" #editor></div>
</div> </div>

8
src/Squidex/app/shared/components/rich-editor.component.scss

@ -1,8 +1,10 @@
@import '_mixins'; @import '_mixins';
@import '_vars'; @import '_vars';
.drop-container {
min-height: 401px;
}
.editor { .editor {
background: $color-dark-foreground; height: 300px;
border: 1px solid $color-input;
height: 30rem;
} }

13
src/Squidex/app/shared/components/rich-editor.component.ts

@ -64,7 +64,8 @@ export class RichEditorComponent extends StatefulControlComponent<undefined, str
public ngOnDestroy() { public ngOnDestroy() {
if (this.tinyEditor) { if (this.tinyEditor) {
tinymce.remove(this.editor); this.tinyEditor.destroy();
this.tinyEditor = null;
} }
} }
@ -76,6 +77,14 @@ export class RichEditorComponent extends StatefulControlComponent<undefined, str
}); });
} }
public reset() {
this.ngOnDestroy();
setTimeout(() => {
this.ngAfterViewInit();
});
}
private showSelector = () => { private showSelector = () => {
if (this.isDisabled) { if (this.isDisabled) {
return; return;
@ -91,6 +100,8 @@ export class RichEditorComponent extends StatefulControlComponent<undefined, str
convert_fonts_to_spans: true, convert_fonts_to_spans: true,
convert_urls: false, convert_urls: false,
plugins: 'code image media link lists advlist paste', plugins: 'code image media link lists advlist paste',
min_height: 300,
max_height: 800,
removed_menuitems: 'newdocument', removed_menuitems: 'newdocument',
resize: true, resize: true,
toolbar: 'undo redo | styleselect | bold italic | alignleft aligncenter | bullist numlist outdent indent | link image media | assets', toolbar: 'undo redo | styleselect | bold italic | alignleft aligncenter | bullist numlist outdent indent | link image media | assets',

Loading…
Cancel
Save