-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy patheditor.component.ts
More file actions
40 lines (37 loc) · 1.42 KB
/
editor.component.ts
File metadata and controls
40 lines (37 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* eslint-disable @typescript-eslint/no-parameter-properties */
import {Component, forwardRef, Input} from '@angular/core';
import {NG_VALUE_ACCESSOR} from '@angular/forms';
import {isTextarea, uuid} from '../utils/Utils';
import {EditorDirective} from "./editor.directive";
const EDITOR_COMPONENT_VALUE_ACCESSOR = {
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => EditorComponent),
multi: true
};
@Component({
selector: 'editor',
template: '',
styles: [ ':host { display: block; }' ],
providers: [ EDITOR_COMPONENT_VALUE_ACCESSOR ],
standalone: true
})
export class EditorComponent extends EditorDirective {
@Input() public id = '';
@Input() public tagName: string | undefined;
protected override createElement() {
this.id = this.id || uuid('tiny-angular');
const tagName = typeof this.tagName === 'string' ? this.tagName : 'div';
this._element = document.createElement(this.inline ? tagName : 'textarea');
if (this._element) {
if (document.getElementById(this.id)) {
/* eslint no-console: ["error", { allow: ["warn"] }] */
console.warn(`TinyMCE-Angular: an element with id [${this.id}] already exists. Editors with duplicate Id will not be able to mount`);
}
this._element.id = this.id;
if (isTextarea(this._element)) {
this._element.style.visibility = 'hidden';
}
this._elementRef.nativeElement.appendChild(this._element);
}
}
}