@kolkov/angular-editor 3.0.0-beta.2 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +69 -1
- package/README.md +15 -10
- package/assets/icons/icons.svg +2 -2
- package/fesm2022/kolkov-angular-editor.mjs +1360 -0
- package/fesm2022/kolkov-angular-editor.mjs.map +1 -0
- package/index.d.ts +412 -0
- package/package.json +10 -16
- package/themes/default.scss +22 -22
- package/esm2020/kolkov-angular-editor.mjs +0 -5
- package/esm2020/lib/ae-button/ae-button.component.mjs +0 -21
- package/esm2020/lib/ae-select/ae-select.component.mjs +0 -185
- package/esm2020/lib/ae-toolbar/ae-toolbar.component.mjs +0 -365
- package/esm2020/lib/ae-toolbar-set/ae-toolbar-set.component.mjs +0 -15
- package/esm2020/lib/angular-editor.module.mjs +0 -27
- package/esm2020/lib/angular-editor.service.mjs +0 -275
- package/esm2020/lib/config.mjs +0 -36
- package/esm2020/lib/editor/angular-editor.component.mjs +0 -415
- package/esm2020/lib/utils.mjs +0 -4
- package/esm2020/public-api.mjs +0 -11
- package/fesm2015/kolkov-angular-editor.mjs +0 -1325
- package/fesm2015/kolkov-angular-editor.mjs.map +0 -1
- package/fesm2020/kolkov-angular-editor.mjs +0 -1319
- package/fesm2020/kolkov-angular-editor.mjs.map +0 -1
- package/kolkov-angular-editor.d.ts +0 -5
- package/lib/ae-button/ae-button.component.d.ts +0 -7
- package/lib/ae-select/ae-select.component.d.ts +0 -46
- package/lib/ae-toolbar/ae-toolbar.component.d.ts +0 -97
- package/lib/ae-toolbar-set/ae-toolbar-set.component.d.ts +0 -6
- package/lib/angular-editor.module.d.ts +0 -13
- package/lib/angular-editor.service.d.ts +0 -87
- package/lib/config.d.ts +0 -39
- package/lib/editor/angular-editor.component.d.ts +0 -133
- package/lib/utils.d.ts +0 -1
- package/public-api.d.ts +0 -8
|
@@ -0,0 +1,1360 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { DOCUMENT, Inject, Injectable, EventEmitter, forwardRef, HostListener, ViewChild, Output, HostBinding, Input, Component, SecurityContext, ContentChild, Attribute, ViewEncapsulation, NgModule } from '@angular/core';
|
|
3
|
+
import * as i1 from '@angular/common/http';
|
|
4
|
+
import * as i3 from '@angular/forms';
|
|
5
|
+
import { NG_VALUE_ACCESSOR, FormsModule, ReactiveFormsModule } from '@angular/forms';
|
|
6
|
+
import * as i2 from '@angular/platform-browser';
|
|
7
|
+
import * as i1$1 from '@angular/common';
|
|
8
|
+
import { CommonModule } from '@angular/common';
|
|
9
|
+
|
|
10
|
+
class AngularEditorService {
|
|
11
|
+
http;
|
|
12
|
+
doc;
|
|
13
|
+
savedSelection;
|
|
14
|
+
selectedText;
|
|
15
|
+
uploadUrl;
|
|
16
|
+
uploadWithCredentials;
|
|
17
|
+
constructor(http, doc) {
|
|
18
|
+
this.http = http;
|
|
19
|
+
this.doc = doc;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Executed command from editor header buttons exclude toggleEditorMode
|
|
23
|
+
* @param command string from triggerCommand
|
|
24
|
+
* @param value
|
|
25
|
+
*/
|
|
26
|
+
executeCommand(command, value) {
|
|
27
|
+
const commands = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'pre'];
|
|
28
|
+
if (commands.includes(command)) {
|
|
29
|
+
this.doc.execCommand('formatBlock', false, command);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
this.doc.execCommand(command, false, value);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Create URL link
|
|
36
|
+
* @param url string from UI prompt
|
|
37
|
+
*/
|
|
38
|
+
createLink(url) {
|
|
39
|
+
if (!url.includes('http')) {
|
|
40
|
+
this.doc.execCommand('createlink', false, url);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
const newUrl = '<a href="' + url + '" target="_blank">' + this.selectedText + '</a>';
|
|
44
|
+
this.insertHtml(newUrl);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* insert color either font or background
|
|
49
|
+
*
|
|
50
|
+
* @param color color to be inserted
|
|
51
|
+
* @param where where the color has to be inserted either text/background
|
|
52
|
+
*/
|
|
53
|
+
insertColor(color, where) {
|
|
54
|
+
const restored = this.restoreSelection();
|
|
55
|
+
if (restored) {
|
|
56
|
+
if (where === 'textColor') {
|
|
57
|
+
this.doc.execCommand('foreColor', false, color);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
this.doc.execCommand('hiliteColor', false, color);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Set font name
|
|
66
|
+
* @param fontName string
|
|
67
|
+
*/
|
|
68
|
+
setFontName(fontName) {
|
|
69
|
+
this.doc.execCommand('fontName', false, fontName);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Set font size
|
|
73
|
+
* @param fontSize string
|
|
74
|
+
*/
|
|
75
|
+
setFontSize(fontSize) {
|
|
76
|
+
this.doc.execCommand('fontSize', false, fontSize);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Create raw HTML
|
|
80
|
+
* @param html HTML string
|
|
81
|
+
*/
|
|
82
|
+
insertHtml(html) {
|
|
83
|
+
const isHTMLInserted = this.doc.execCommand('insertHTML', false, html);
|
|
84
|
+
if (!isHTMLInserted) {
|
|
85
|
+
throw new Error('Unable to perform the operation');
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* save selection when the editor is focussed out
|
|
90
|
+
*/
|
|
91
|
+
saveSelection = () => {
|
|
92
|
+
if (this.doc.getSelection) {
|
|
93
|
+
const sel = this.doc.getSelection();
|
|
94
|
+
if (sel.getRangeAt && sel.rangeCount) {
|
|
95
|
+
this.savedSelection = sel.getRangeAt(0);
|
|
96
|
+
this.selectedText = sel.toString();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
else if (this.doc.getSelection && this.doc.createRange) {
|
|
100
|
+
this.savedSelection = document.createRange();
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
this.savedSelection = null;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* restore selection when the editor is focused in
|
|
108
|
+
*
|
|
109
|
+
* saved selection when the editor is focused out
|
|
110
|
+
*/
|
|
111
|
+
restoreSelection() {
|
|
112
|
+
if (this.savedSelection) {
|
|
113
|
+
if (this.doc.getSelection) {
|
|
114
|
+
const sel = this.doc.getSelection();
|
|
115
|
+
sel.removeAllRanges();
|
|
116
|
+
sel.addRange(this.savedSelection);
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
else if (this.doc.getSelection /*&& this.savedSelection.select*/) {
|
|
120
|
+
// this.savedSelection.select();
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* setTimeout used for execute 'saveSelection' method in next event loop iteration
|
|
130
|
+
*/
|
|
131
|
+
executeInNextQueueIteration(callbackFn, timeout = 1e2) {
|
|
132
|
+
setTimeout(callbackFn, timeout);
|
|
133
|
+
}
|
|
134
|
+
/** check any selection is made or not */
|
|
135
|
+
checkSelection() {
|
|
136
|
+
const selectedText = this.savedSelection.toString();
|
|
137
|
+
if (selectedText.length === 0) {
|
|
138
|
+
throw new Error('No Selection Made');
|
|
139
|
+
}
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Upload file to uploadUrl
|
|
144
|
+
* @param file The file
|
|
145
|
+
*/
|
|
146
|
+
uploadImage(file) {
|
|
147
|
+
const uploadData = new FormData();
|
|
148
|
+
uploadData.append('file', file, file.name);
|
|
149
|
+
return this.http.post(this.uploadUrl, uploadData, {
|
|
150
|
+
reportProgress: true,
|
|
151
|
+
observe: 'events',
|
|
152
|
+
withCredentials: this.uploadWithCredentials,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Insert image with Url
|
|
157
|
+
* @param imageUrl The imageUrl.
|
|
158
|
+
*/
|
|
159
|
+
insertImage(imageUrl) {
|
|
160
|
+
this.doc.execCommand('insertImage', false, imageUrl);
|
|
161
|
+
}
|
|
162
|
+
setDefaultParagraphSeparator(separator) {
|
|
163
|
+
this.doc.execCommand('defaultParagraphSeparator', false, separator);
|
|
164
|
+
}
|
|
165
|
+
createCustomClass(customClass) {
|
|
166
|
+
let newTag = this.selectedText;
|
|
167
|
+
if (customClass) {
|
|
168
|
+
const tagName = customClass.tag ? customClass.tag : 'span';
|
|
169
|
+
newTag = '<' + tagName + ' class="' + customClass.class + '">' + this.selectedText + '</' + tagName + '>';
|
|
170
|
+
}
|
|
171
|
+
this.insertHtml(newTag);
|
|
172
|
+
}
|
|
173
|
+
insertVideo(videoUrl) {
|
|
174
|
+
if (videoUrl.match('www.youtube.com')) {
|
|
175
|
+
this.insertYouTubeVideoTag(videoUrl);
|
|
176
|
+
}
|
|
177
|
+
if (videoUrl.match('vimeo.com')) {
|
|
178
|
+
this.insertVimeoVideoTag(videoUrl);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
insertYouTubeVideoTag(videoUrl) {
|
|
182
|
+
const id = videoUrl.split('v=')[1];
|
|
183
|
+
const imageUrl = `https://img.youtube.com/vi/${id}/0.jpg`;
|
|
184
|
+
const thumbnail = `
|
|
185
|
+
<div style='position: relative'>
|
|
186
|
+
<a href='${videoUrl}' target='_blank'>
|
|
187
|
+
<img src="${imageUrl}" alt="click to watch"/>
|
|
188
|
+
<img style='position: absolute; left:200px; top:140px'
|
|
189
|
+
src="https://img.icons8.com/color/96/000000/youtube-play.png"/>
|
|
190
|
+
</a>
|
|
191
|
+
</div>`;
|
|
192
|
+
this.insertHtml(thumbnail);
|
|
193
|
+
}
|
|
194
|
+
insertVimeoVideoTag(videoUrl) {
|
|
195
|
+
const sub = this.http.get(`https://vimeo.com/api/oembed.json?url=${videoUrl}`).subscribe(data => {
|
|
196
|
+
const imageUrl = data.thumbnail_url_with_play_button;
|
|
197
|
+
const thumbnail = `<div>
|
|
198
|
+
<a href='${videoUrl}' target='_blank'>
|
|
199
|
+
<img src="${imageUrl}" alt="${data.title}"/>
|
|
200
|
+
</a>
|
|
201
|
+
</div>`;
|
|
202
|
+
this.insertHtml(thumbnail);
|
|
203
|
+
sub.unsubscribe();
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
nextNode(node) {
|
|
207
|
+
if (node.hasChildNodes()) {
|
|
208
|
+
return node.firstChild;
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
while (node && !node.nextSibling) {
|
|
212
|
+
node = node.parentNode;
|
|
213
|
+
}
|
|
214
|
+
if (!node) {
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
return node.nextSibling;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
getRangeSelectedNodes(range, includePartiallySelectedContainers) {
|
|
221
|
+
let node = range.startContainer;
|
|
222
|
+
const endNode = range.endContainer;
|
|
223
|
+
let rangeNodes = [];
|
|
224
|
+
// Special case for a range that is contained within a single node
|
|
225
|
+
if (node === endNode) {
|
|
226
|
+
rangeNodes = [node];
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
// Iterate nodes until we hit the end container
|
|
230
|
+
while (node && node !== endNode) {
|
|
231
|
+
rangeNodes.push(node = this.nextNode(node));
|
|
232
|
+
}
|
|
233
|
+
// Add partially selected nodes at the start of the range
|
|
234
|
+
node = range.startContainer;
|
|
235
|
+
while (node && node !== range.commonAncestorContainer) {
|
|
236
|
+
rangeNodes.unshift(node);
|
|
237
|
+
node = node.parentNode;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
// Add ancestors of the range container, if required
|
|
241
|
+
if (includePartiallySelectedContainers) {
|
|
242
|
+
node = range.commonAncestorContainer;
|
|
243
|
+
while (node) {
|
|
244
|
+
rangeNodes.push(node);
|
|
245
|
+
node = node.parentNode;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return rangeNodes;
|
|
249
|
+
}
|
|
250
|
+
getSelectedNodes() {
|
|
251
|
+
const nodes = [];
|
|
252
|
+
if (this.doc.getSelection) {
|
|
253
|
+
const sel = this.doc.getSelection();
|
|
254
|
+
for (let i = 0, len = sel.rangeCount; i < len; ++i) {
|
|
255
|
+
nodes.push.apply(nodes, this.getRangeSelectedNodes(sel.getRangeAt(i), true));
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return nodes;
|
|
259
|
+
}
|
|
260
|
+
replaceWithOwnChildren(el) {
|
|
261
|
+
const parent = el.parentNode;
|
|
262
|
+
while (el.hasChildNodes()) {
|
|
263
|
+
parent.insertBefore(el.firstChild, el);
|
|
264
|
+
}
|
|
265
|
+
parent.removeChild(el);
|
|
266
|
+
}
|
|
267
|
+
removeSelectedElements(tagNames) {
|
|
268
|
+
const tagNamesArray = tagNames.toLowerCase().split(',');
|
|
269
|
+
this.getSelectedNodes().forEach((node) => {
|
|
270
|
+
if (node.nodeType === 1 &&
|
|
271
|
+
tagNamesArray.indexOf(node.tagName.toLowerCase()) > -1) {
|
|
272
|
+
// Remove the node and replace it with its children
|
|
273
|
+
this.replaceWithOwnChildren(node);
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.13", ngImport: i0, type: AngularEditorService, deps: [{ token: i1.HttpClient }, { token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
278
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.13", ngImport: i0, type: AngularEditorService });
|
|
279
|
+
}
|
|
280
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.13", ngImport: i0, type: AngularEditorService, decorators: [{
|
|
281
|
+
type: Injectable
|
|
282
|
+
}], ctorParameters: () => [{ type: i1.HttpClient }, { type: undefined, decorators: [{
|
|
283
|
+
type: Inject,
|
|
284
|
+
args: [DOCUMENT]
|
|
285
|
+
}] }] });
|
|
286
|
+
|
|
287
|
+
const angularEditorConfig = {
|
|
288
|
+
editable: true,
|
|
289
|
+
spellcheck: true,
|
|
290
|
+
height: 'auto',
|
|
291
|
+
minHeight: '0',
|
|
292
|
+
maxHeight: 'auto',
|
|
293
|
+
width: 'auto',
|
|
294
|
+
minWidth: '0',
|
|
295
|
+
translate: 'yes',
|
|
296
|
+
enableToolbar: true,
|
|
297
|
+
showToolbar: true,
|
|
298
|
+
placeholder: 'Enter text here...',
|
|
299
|
+
defaultParagraphSeparator: '',
|
|
300
|
+
defaultFontName: '',
|
|
301
|
+
defaultFontSize: '',
|
|
302
|
+
fonts: [
|
|
303
|
+
{ class: 'arial', name: 'Arial' },
|
|
304
|
+
{ class: 'times-new-roman', name: 'Times New Roman' },
|
|
305
|
+
{ class: 'calibri', name: 'Calibri' },
|
|
306
|
+
{ class: 'comic-sans-ms', name: 'Comic Sans MS' }
|
|
307
|
+
],
|
|
308
|
+
uploadUrl: 'v1/image',
|
|
309
|
+
uploadWithCredentials: false,
|
|
310
|
+
sanitize: true,
|
|
311
|
+
toolbarPosition: 'top',
|
|
312
|
+
outline: true,
|
|
313
|
+
/*toolbarHiddenButtons: [
|
|
314
|
+
['bold', 'italic', 'underline', 'strikeThrough', 'superscript', 'subscript'],
|
|
315
|
+
['heading', 'fontName', 'fontSize', 'color'],
|
|
316
|
+
['justifyLeft', 'justifyCenter', 'justifyRight', 'justifyFull', 'indent', 'outdent'],
|
|
317
|
+
['cut', 'copy', 'delete', 'removeFormat', 'undo', 'redo'],
|
|
318
|
+
['paragraph', 'blockquote', 'removeBlockquote', 'horizontalLine', 'orderedList', 'unorderedList'],
|
|
319
|
+
['link', 'unlink', 'image', 'video']
|
|
320
|
+
]*/
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
function isDefined(value) {
|
|
324
|
+
return value !== undefined && value !== null;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
class AeSelectComponent {
|
|
328
|
+
elRef;
|
|
329
|
+
r;
|
|
330
|
+
options = [];
|
|
331
|
+
// eslint-disable-next-line @angular-eslint/no-input-rename
|
|
332
|
+
isHidden;
|
|
333
|
+
selectedOption;
|
|
334
|
+
disabled = false;
|
|
335
|
+
optionId = 0;
|
|
336
|
+
get label() {
|
|
337
|
+
return this.selectedOption && this.selectedOption.hasOwnProperty('label') ? this.selectedOption.label : 'Select';
|
|
338
|
+
}
|
|
339
|
+
opened = false;
|
|
340
|
+
get value() {
|
|
341
|
+
return this.selectedOption.value;
|
|
342
|
+
}
|
|
343
|
+
hidden = 'inline-block';
|
|
344
|
+
// eslint-disable-next-line @angular-eslint/no-output-native, @angular-eslint/no-output-rename
|
|
345
|
+
changeEvent = new EventEmitter();
|
|
346
|
+
labelButton;
|
|
347
|
+
constructor(elRef, r) {
|
|
348
|
+
this.elRef = elRef;
|
|
349
|
+
this.r = r;
|
|
350
|
+
}
|
|
351
|
+
ngOnInit() {
|
|
352
|
+
this.selectedOption = this.options[0];
|
|
353
|
+
if (isDefined(this.isHidden) && this.isHidden) {
|
|
354
|
+
this.hide();
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
hide() {
|
|
358
|
+
this.hidden = 'none';
|
|
359
|
+
}
|
|
360
|
+
optionSelect(option, event) {
|
|
361
|
+
//console.log(event.button, event.buttons);
|
|
362
|
+
if (event.buttons !== 1) {
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
event.preventDefault();
|
|
366
|
+
event.stopPropagation();
|
|
367
|
+
this.setValue(option.value);
|
|
368
|
+
this.onChange(this.selectedOption.value);
|
|
369
|
+
this.changeEvent.emit(this.selectedOption.value);
|
|
370
|
+
this.onTouched();
|
|
371
|
+
this.opened = false;
|
|
372
|
+
}
|
|
373
|
+
toggleOpen(event) {
|
|
374
|
+
// event.stopPropagation();
|
|
375
|
+
if (this.disabled) {
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
this.opened = !this.opened;
|
|
379
|
+
}
|
|
380
|
+
onClick($event) {
|
|
381
|
+
if (!this.elRef.nativeElement.contains($event.target)) {
|
|
382
|
+
this.close();
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
close() {
|
|
386
|
+
this.opened = false;
|
|
387
|
+
}
|
|
388
|
+
get isOpen() {
|
|
389
|
+
return this.opened;
|
|
390
|
+
}
|
|
391
|
+
writeValue(value) {
|
|
392
|
+
if (!value || typeof value !== 'string') {
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
this.setValue(value);
|
|
396
|
+
}
|
|
397
|
+
setValue(value) {
|
|
398
|
+
let index = 0;
|
|
399
|
+
const selectedEl = this.options.find((el, i) => {
|
|
400
|
+
index = i;
|
|
401
|
+
return el.value === value;
|
|
402
|
+
});
|
|
403
|
+
if (selectedEl) {
|
|
404
|
+
this.selectedOption = selectedEl;
|
|
405
|
+
this.optionId = index;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
onChange = () => {
|
|
409
|
+
};
|
|
410
|
+
onTouched = () => {
|
|
411
|
+
};
|
|
412
|
+
registerOnChange(fn) {
|
|
413
|
+
this.onChange = fn;
|
|
414
|
+
}
|
|
415
|
+
registerOnTouched(fn) {
|
|
416
|
+
this.onTouched = fn;
|
|
417
|
+
}
|
|
418
|
+
setDisabledState(isDisabled) {
|
|
419
|
+
this.labelButton.nativeElement.disabled = isDisabled;
|
|
420
|
+
const div = this.labelButton.nativeElement;
|
|
421
|
+
const action = isDisabled ? 'addClass' : 'removeClass';
|
|
422
|
+
this.r[action](div, 'disabled');
|
|
423
|
+
this.disabled = isDisabled;
|
|
424
|
+
}
|
|
425
|
+
handleKeyDown($event) {
|
|
426
|
+
if (!this.opened) {
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
// console.log($event.key);
|
|
430
|
+
// if (KeyCode[$event.key]) {
|
|
431
|
+
switch ($event.key) {
|
|
432
|
+
case 'ArrowDown':
|
|
433
|
+
this._handleArrowDown($event);
|
|
434
|
+
break;
|
|
435
|
+
case 'ArrowUp':
|
|
436
|
+
this._handleArrowUp($event);
|
|
437
|
+
break;
|
|
438
|
+
case 'Space':
|
|
439
|
+
this._handleSpace($event);
|
|
440
|
+
break;
|
|
441
|
+
case 'Enter':
|
|
442
|
+
this._handleEnter($event);
|
|
443
|
+
break;
|
|
444
|
+
case 'Tab':
|
|
445
|
+
this._handleTab($event);
|
|
446
|
+
break;
|
|
447
|
+
case 'Escape':
|
|
448
|
+
this.close();
|
|
449
|
+
$event.preventDefault();
|
|
450
|
+
break;
|
|
451
|
+
case 'Backspace':
|
|
452
|
+
this._handleBackspace();
|
|
453
|
+
break;
|
|
454
|
+
}
|
|
455
|
+
// } else if ($event.key && $event.key.length === 1) {
|
|
456
|
+
// this._keyPress$.next($event.key.toLocaleLowerCase());
|
|
457
|
+
// }
|
|
458
|
+
}
|
|
459
|
+
_handleArrowDown($event) {
|
|
460
|
+
if (this.optionId < this.options.length - 1) {
|
|
461
|
+
this.optionId++;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
_handleArrowUp($event) {
|
|
465
|
+
if (this.optionId >= 1) {
|
|
466
|
+
this.optionId--;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
_handleSpace($event) {
|
|
470
|
+
}
|
|
471
|
+
_handleEnter($event) {
|
|
472
|
+
this.optionSelect(this.options[this.optionId], $event);
|
|
473
|
+
}
|
|
474
|
+
_handleTab($event) {
|
|
475
|
+
}
|
|
476
|
+
_handleBackspace() {
|
|
477
|
+
}
|
|
478
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.13", ngImport: i0, type: AeSelectComponent, deps: [{ token: i0.ElementRef }, { token: i0.Renderer2 }], target: i0.ɵɵFactoryTarget.Component });
|
|
479
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.13", type: AeSelectComponent, isStandalone: false, selector: "ae-select", inputs: { options: "options", isHidden: ["hidden", "isHidden"] }, outputs: { changeEvent: "change" }, host: { listeners: { "document:click": "onClick($event)", "keydown": "handleKeyDown($event)" }, properties: { "style.display": "this.hidden" } }, providers: [
|
|
480
|
+
{
|
|
481
|
+
provide: NG_VALUE_ACCESSOR,
|
|
482
|
+
useExisting: forwardRef(() => AeSelectComponent),
|
|
483
|
+
multi: true,
|
|
484
|
+
}
|
|
485
|
+
], viewQueries: [{ propertyName: "labelButton", first: true, predicate: ["labelButton"], descendants: true, static: true }], ngImport: i0, template: "<span class=\"ae-picker\" [ngClass]=\"{'ae-expanded':isOpen}\">\n <button [tabIndex]=\"-1\" #labelButton tabindex=\"-1\" type=\"button\" role=\"button\" class=\"ae-picker-label\" (click)=\"toggleOpen($event);\">{{label}}\n <svg>\n <use [attr.href]=\"'assets/ae-icons/icons.svg#sort'\" [attr.xlink:href]=\"'assets/ae-icons/icons.svg#sort'\"></use>\n </svg>\n </button>\n <span class=\"ae-picker-options\">\n <span tabindex=\"-1\" type=\"button\" role=\"button\" class=\"ae-picker-item\"\n *ngFor=\"let item of options; let i = index\"\n [ngClass]=\"{'selected': item.value === value, 'focused': i === optionId}\"\n (mousedown)=\"optionSelect(item, $event)\">\n {{item.label}}\n </span>\n <span class=\"dropdown-item\" *ngIf=\"!options.length\">No items for select</span>\n </span>\n</span>\n", styles: ["a{cursor:pointer}svg{width:100%;height:100%}.ae-picker{color:var(--ae-picker-color, #444);display:inline-block;float:left;width:100%;position:relative;vertical-align:middle}.ae-picker-label{cursor:pointer;display:inline-block;padding-left:8px;padding-right:10px;position:relative;width:100%;line-height:1.8rem;vertical-align:middle;font-size:85%;text-align:left;background-color:var(--ae-picker-label-color, white);min-width:2rem;float:left;border:1px solid #ddd;border-radius:var(--ae-button-radius, 4px);text-overflow:clip;overflow:hidden;white-space:nowrap;height:2rem}.ae-picker-label:before{content:\"\";position:absolute;right:0;top:0;width:20px;height:100%;background:linear-gradient(to right,var(--ae-picker-label-color, white),var(--ae-picker-label-color, white) 100%)}.ae-picker-label:focus{outline:none}.ae-picker-label:hover{cursor:pointer;background-color:#f1f1f1;transition:.2s ease}.ae-picker-label:hover:before{background:linear-gradient(to right,#f5f5f5 100%,#fff)}.ae-picker-label:disabled{background-color:#f5f5f5;pointer-events:none;cursor:not-allowed}.ae-picker-label:disabled:before{background:linear-gradient(to right,#f5f5f5 100%,#fff)}.ae-picker-label svg{position:absolute;right:0;width:1rem}.ae-picker-label svg:not(:root){overflow:hidden}.ae-picker-label svg .ae-stroke{fill:none;stroke:#444;stroke-linecap:round;stroke-linejoin:round;stroke-width:2}.ae-picker-options{background-color:var(--ae-picker-option-bg-color, #fff);display:none;min-width:100%;position:absolute;white-space:nowrap;z-index:3;border:1px solid transparent;box-shadow:#0003 0 2px 8px}.ae-picker-options .ae-picker-item{cursor:pointer;display:block;padding:5px;z-index:3;text-align:left;background-color:transparent;min-width:2rem;border:0 solid #ddd}.ae-picker-options .ae-picker-item.selected{color:#06c;background-color:var(--ae-picker-option-active-bg-color, #fff4c2)}.ae-picker-options .ae-picker-item.focused{background-color:var(--ae-picker-option-focused-bg-color, #fbf9b0)}.ae-picker-options .ae-picker-item:hover{background-color:var(--ae-picker-option-hover-bg-color, #fffa98)}.ae-expanded{display:block;margin-top:-1px;z-index:1}.ae-expanded .ae-picker-label{color:#ccc;z-index:2}.ae-expanded .ae-picker-label svg{color:#ccc;z-index:2}.ae-expanded .ae-picker-label svg .ae-stroke{stroke:#ccc}.ae-expanded .ae-picker-options{display:flex;flex-direction:column;margin-top:-1px;top:100%;z-index:3;border-color:#ccc}\n"], dependencies: [{ kind: "directive", type: i1$1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1$1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i1$1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }] });
|
|
486
|
+
}
|
|
487
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.13", ngImport: i0, type: AeSelectComponent, decorators: [{
|
|
488
|
+
type: Component,
|
|
489
|
+
args: [{ selector: 'ae-select', providers: [
|
|
490
|
+
{
|
|
491
|
+
provide: NG_VALUE_ACCESSOR,
|
|
492
|
+
useExisting: forwardRef(() => AeSelectComponent),
|
|
493
|
+
multi: true,
|
|
494
|
+
}
|
|
495
|
+
], standalone: false, template: "<span class=\"ae-picker\" [ngClass]=\"{'ae-expanded':isOpen}\">\n <button [tabIndex]=\"-1\" #labelButton tabindex=\"-1\" type=\"button\" role=\"button\" class=\"ae-picker-label\" (click)=\"toggleOpen($event);\">{{label}}\n <svg>\n <use [attr.href]=\"'assets/ae-icons/icons.svg#sort'\" [attr.xlink:href]=\"'assets/ae-icons/icons.svg#sort'\"></use>\n </svg>\n </button>\n <span class=\"ae-picker-options\">\n <span tabindex=\"-1\" type=\"button\" role=\"button\" class=\"ae-picker-item\"\n *ngFor=\"let item of options; let i = index\"\n [ngClass]=\"{'selected': item.value === value, 'focused': i === optionId}\"\n (mousedown)=\"optionSelect(item, $event)\">\n {{item.label}}\n </span>\n <span class=\"dropdown-item\" *ngIf=\"!options.length\">No items for select</span>\n </span>\n</span>\n", styles: ["a{cursor:pointer}svg{width:100%;height:100%}.ae-picker{color:var(--ae-picker-color, #444);display:inline-block;float:left;width:100%;position:relative;vertical-align:middle}.ae-picker-label{cursor:pointer;display:inline-block;padding-left:8px;padding-right:10px;position:relative;width:100%;line-height:1.8rem;vertical-align:middle;font-size:85%;text-align:left;background-color:var(--ae-picker-label-color, white);min-width:2rem;float:left;border:1px solid #ddd;border-radius:var(--ae-button-radius, 4px);text-overflow:clip;overflow:hidden;white-space:nowrap;height:2rem}.ae-picker-label:before{content:\"\";position:absolute;right:0;top:0;width:20px;height:100%;background:linear-gradient(to right,var(--ae-picker-label-color, white),var(--ae-picker-label-color, white) 100%)}.ae-picker-label:focus{outline:none}.ae-picker-label:hover{cursor:pointer;background-color:#f1f1f1;transition:.2s ease}.ae-picker-label:hover:before{background:linear-gradient(to right,#f5f5f5 100%,#fff)}.ae-picker-label:disabled{background-color:#f5f5f5;pointer-events:none;cursor:not-allowed}.ae-picker-label:disabled:before{background:linear-gradient(to right,#f5f5f5 100%,#fff)}.ae-picker-label svg{position:absolute;right:0;width:1rem}.ae-picker-label svg:not(:root){overflow:hidden}.ae-picker-label svg .ae-stroke{fill:none;stroke:#444;stroke-linecap:round;stroke-linejoin:round;stroke-width:2}.ae-picker-options{background-color:var(--ae-picker-option-bg-color, #fff);display:none;min-width:100%;position:absolute;white-space:nowrap;z-index:3;border:1px solid transparent;box-shadow:#0003 0 2px 8px}.ae-picker-options .ae-picker-item{cursor:pointer;display:block;padding:5px;z-index:3;text-align:left;background-color:transparent;min-width:2rem;border:0 solid #ddd}.ae-picker-options .ae-picker-item.selected{color:#06c;background-color:var(--ae-picker-option-active-bg-color, #fff4c2)}.ae-picker-options .ae-picker-item.focused{background-color:var(--ae-picker-option-focused-bg-color, #fbf9b0)}.ae-picker-options .ae-picker-item:hover{background-color:var(--ae-picker-option-hover-bg-color, #fffa98)}.ae-expanded{display:block;margin-top:-1px;z-index:1}.ae-expanded .ae-picker-label{color:#ccc;z-index:2}.ae-expanded .ae-picker-label svg{color:#ccc;z-index:2}.ae-expanded .ae-picker-label svg .ae-stroke{stroke:#ccc}.ae-expanded .ae-picker-options{display:flex;flex-direction:column;margin-top:-1px;top:100%;z-index:3;border-color:#ccc}\n"] }]
|
|
496
|
+
}], ctorParameters: () => [{ type: i0.ElementRef }, { type: i0.Renderer2 }], propDecorators: { options: [{
|
|
497
|
+
type: Input
|
|
498
|
+
}], isHidden: [{
|
|
499
|
+
type: Input,
|
|
500
|
+
args: ['hidden']
|
|
501
|
+
}], hidden: [{
|
|
502
|
+
type: HostBinding,
|
|
503
|
+
args: ['style.display']
|
|
504
|
+
}], changeEvent: [{
|
|
505
|
+
type: Output,
|
|
506
|
+
args: ['change']
|
|
507
|
+
}], labelButton: [{
|
|
508
|
+
type: ViewChild,
|
|
509
|
+
args: ['labelButton', { static: true }]
|
|
510
|
+
}], onClick: [{
|
|
511
|
+
type: HostListener,
|
|
512
|
+
args: ['document:click', ['$event']]
|
|
513
|
+
}], handleKeyDown: [{
|
|
514
|
+
type: HostListener,
|
|
515
|
+
args: ['keydown', ['$event']]
|
|
516
|
+
}] } });
|
|
517
|
+
|
|
518
|
+
class AeButtonComponent {
|
|
519
|
+
iconName = '';
|
|
520
|
+
constructor() {
|
|
521
|
+
}
|
|
522
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.13", ngImport: i0, type: AeButtonComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
523
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.13", type: AeButtonComponent, isStandalone: false, selector: "ae-button, button[aeButton]", inputs: { iconName: "iconName" }, host: { properties: { "tabIndex": "-1", "type": "\"button\"" }, classAttribute: "angular-editor-button" }, ngImport: i0, template: "<ng-container *ngIf=\"iconName; else contentTemplate\">\n <svg>\n <use [attr.href]=\"'assets/ae-icons/icons.svg#' + iconName\" [attr.xlink:href]=\"'assets/ae-icons/icons.svg#' + iconName\"></use>\n </svg>\n</ng-container>\n<ng-template #contentTemplate>\n <ng-content></ng-content>\n</ng-template>\n", styles: ["a{cursor:pointer}:host.angular-editor-button{background-color:var(--ae-button-bg-color, white);vertical-align:middle;border:var(--ae-button-border, 1px solid #ddd);border-radius:var(--ae-button-radius, 4px);padding:.4rem;float:left;width:2rem;height:2rem}:host.angular-editor-button svg{width:100%;height:100%}:host.angular-editor-button:hover{cursor:pointer;background-color:var(--ae-button-hover-bg-color, #f1f1f1);transition:.2s ease}:host.angular-editor-button:focus,:host.angular-editor-button.focus{outline:0}:host.angular-editor-button:disabled{background-color:var(--ae-button-disabled-bg-color, #f5f5f5);pointer-events:none;cursor:not-allowed}:host.angular-editor-button:disabled>.color-label{pointer-events:none;cursor:not-allowed}:host.angular-editor-button:disabled>.color-label.foreground :after{background:#555}:host.angular-editor-button:disabled>.color-label.background{background:#555}:host.angular-editor-button.active{background:var(--ae-button-active-bg-color, #fffbd3)}:host.angular-editor-button.active:hover{background-color:var(--ae-button-active-hover-bg-color, #fffaad)}\n"], dependencies: [{ kind: "directive", type: i1$1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }] });
|
|
524
|
+
}
|
|
525
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.13", ngImport: i0, type: AeButtonComponent, decorators: [{
|
|
526
|
+
type: Component,
|
|
527
|
+
args: [{ selector: 'ae-button, button[aeButton]', host: {
|
|
528
|
+
'class': 'angular-editor-button',
|
|
529
|
+
'[tabIndex]': '-1',
|
|
530
|
+
'[type]': '"button"',
|
|
531
|
+
}, standalone: false, template: "<ng-container *ngIf=\"iconName; else contentTemplate\">\n <svg>\n <use [attr.href]=\"'assets/ae-icons/icons.svg#' + iconName\" [attr.xlink:href]=\"'assets/ae-icons/icons.svg#' + iconName\"></use>\n </svg>\n</ng-container>\n<ng-template #contentTemplate>\n <ng-content></ng-content>\n</ng-template>\n", styles: ["a{cursor:pointer}:host.angular-editor-button{background-color:var(--ae-button-bg-color, white);vertical-align:middle;border:var(--ae-button-border, 1px solid #ddd);border-radius:var(--ae-button-radius, 4px);padding:.4rem;float:left;width:2rem;height:2rem}:host.angular-editor-button svg{width:100%;height:100%}:host.angular-editor-button:hover{cursor:pointer;background-color:var(--ae-button-hover-bg-color, #f1f1f1);transition:.2s ease}:host.angular-editor-button:focus,:host.angular-editor-button.focus{outline:0}:host.angular-editor-button:disabled{background-color:var(--ae-button-disabled-bg-color, #f5f5f5);pointer-events:none;cursor:not-allowed}:host.angular-editor-button:disabled>.color-label{pointer-events:none;cursor:not-allowed}:host.angular-editor-button:disabled>.color-label.foreground :after{background:#555}:host.angular-editor-button:disabled>.color-label.background{background:#555}:host.angular-editor-button.active{background:var(--ae-button-active-bg-color, #fffbd3)}:host.angular-editor-button.active:hover{background-color:var(--ae-button-active-hover-bg-color, #fffaad)}\n"] }]
|
|
532
|
+
}], ctorParameters: () => [], propDecorators: { iconName: [{
|
|
533
|
+
type: Input
|
|
534
|
+
}] } });
|
|
535
|
+
|
|
536
|
+
class AeToolbarSetComponent {
|
|
537
|
+
constructor() {
|
|
538
|
+
}
|
|
539
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.13", ngImport: i0, type: AeToolbarSetComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
540
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.13", type: AeToolbarSetComponent, isStandalone: false, selector: "ae-toolbar-set, [aeToolbarSet]", host: { classAttribute: "angular-editor-toolbar-set" }, ngImport: i0, template: "<ng-content></ng-content>\n", styles: ["a{cursor:pointer}:host.angular-editor-toolbar-set{display:flex;gap:1px;width:fit-content;vertical-align:baseline}\n"] });
|
|
541
|
+
}
|
|
542
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.13", ngImport: i0, type: AeToolbarSetComponent, decorators: [{
|
|
543
|
+
type: Component,
|
|
544
|
+
args: [{ selector: 'ae-toolbar-set, [aeToolbarSet]', host: {
|
|
545
|
+
'class': 'angular-editor-toolbar-set'
|
|
546
|
+
}, standalone: false, template: "<ng-content></ng-content>\n", styles: ["a{cursor:pointer}:host.angular-editor-toolbar-set{display:flex;gap:1px;width:fit-content;vertical-align:baseline}\n"] }]
|
|
547
|
+
}], ctorParameters: () => [] });
|
|
548
|
+
|
|
549
|
+
class AeToolbarComponent {
|
|
550
|
+
r;
|
|
551
|
+
editorService;
|
|
552
|
+
er;
|
|
553
|
+
doc;
|
|
554
|
+
htmlMode = false;
|
|
555
|
+
linkSelected = false;
|
|
556
|
+
block = 'default';
|
|
557
|
+
fontName = 'Times New Roman';
|
|
558
|
+
fontSize = '3';
|
|
559
|
+
foreColour;
|
|
560
|
+
backColor;
|
|
561
|
+
headings = [
|
|
562
|
+
{
|
|
563
|
+
label: 'Heading 1',
|
|
564
|
+
value: 'h1',
|
|
565
|
+
},
|
|
566
|
+
{
|
|
567
|
+
label: 'Heading 2',
|
|
568
|
+
value: 'h2',
|
|
569
|
+
},
|
|
570
|
+
{
|
|
571
|
+
label: 'Heading 3',
|
|
572
|
+
value: 'h3',
|
|
573
|
+
},
|
|
574
|
+
{
|
|
575
|
+
label: 'Heading 4',
|
|
576
|
+
value: 'h4',
|
|
577
|
+
},
|
|
578
|
+
{
|
|
579
|
+
label: 'Heading 5',
|
|
580
|
+
value: 'h5',
|
|
581
|
+
},
|
|
582
|
+
{
|
|
583
|
+
label: 'Heading 6',
|
|
584
|
+
value: 'h6',
|
|
585
|
+
},
|
|
586
|
+
{
|
|
587
|
+
label: 'Paragraph',
|
|
588
|
+
value: 'p',
|
|
589
|
+
},
|
|
590
|
+
{
|
|
591
|
+
label: 'Predefined',
|
|
592
|
+
value: 'pre'
|
|
593
|
+
},
|
|
594
|
+
{
|
|
595
|
+
label: 'Standard',
|
|
596
|
+
value: 'div'
|
|
597
|
+
},
|
|
598
|
+
{
|
|
599
|
+
label: 'default',
|
|
600
|
+
value: 'default'
|
|
601
|
+
}
|
|
602
|
+
];
|
|
603
|
+
fontSizes = [
|
|
604
|
+
{
|
|
605
|
+
label: '1',
|
|
606
|
+
value: '1',
|
|
607
|
+
},
|
|
608
|
+
{
|
|
609
|
+
label: '2',
|
|
610
|
+
value: '2',
|
|
611
|
+
},
|
|
612
|
+
{
|
|
613
|
+
label: '3',
|
|
614
|
+
value: '3',
|
|
615
|
+
},
|
|
616
|
+
{
|
|
617
|
+
label: '4',
|
|
618
|
+
value: '4',
|
|
619
|
+
},
|
|
620
|
+
{
|
|
621
|
+
label: '5',
|
|
622
|
+
value: '5',
|
|
623
|
+
},
|
|
624
|
+
{
|
|
625
|
+
label: '6',
|
|
626
|
+
value: '6',
|
|
627
|
+
},
|
|
628
|
+
{
|
|
629
|
+
label: '7',
|
|
630
|
+
value: '7',
|
|
631
|
+
}
|
|
632
|
+
];
|
|
633
|
+
customClassId = '-1';
|
|
634
|
+
// eslint-disable-next-line no-underscore-dangle, id-blacklist, id-match
|
|
635
|
+
_customClasses;
|
|
636
|
+
customClassList = [{ label: '', value: '' }];
|
|
637
|
+
// uploadUrl: string;
|
|
638
|
+
tagMap = {
|
|
639
|
+
BLOCKQUOTE: 'indent',
|
|
640
|
+
A: 'link'
|
|
641
|
+
};
|
|
642
|
+
select = ['H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'P', 'PRE', 'DIV'];
|
|
643
|
+
buttons = ['bold', 'italic', 'underline', 'strikeThrough', 'subscript', 'superscript', 'justifyLeft', 'justifyCenter',
|
|
644
|
+
'justifyRight', 'justifyFull', 'indent', 'outdent', 'insertUnorderedList', 'insertOrderedList', 'link'];
|
|
645
|
+
id;
|
|
646
|
+
uploadUrl;
|
|
647
|
+
upload;
|
|
648
|
+
showToolbar;
|
|
649
|
+
fonts = [{ label: '', value: '' }];
|
|
650
|
+
set customClasses(classes) {
|
|
651
|
+
if (classes) {
|
|
652
|
+
this._customClasses = classes;
|
|
653
|
+
this.customClassList = this._customClasses.map((x, i) => ({ label: x.name, value: i.toString() }));
|
|
654
|
+
this.customClassList.unshift({ label: 'Clear Class', value: '-1' });
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
set defaultFontName(value) {
|
|
658
|
+
if (value) {
|
|
659
|
+
this.fontName = value;
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
set defaultFontSize(value) {
|
|
663
|
+
if (value) {
|
|
664
|
+
this.fontSize = value;
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
hiddenButtons;
|
|
668
|
+
execute = new EventEmitter();
|
|
669
|
+
myInputFile;
|
|
670
|
+
get isLinkButtonDisabled() {
|
|
671
|
+
return this.htmlMode || !Boolean(this.editorService.selectedText);
|
|
672
|
+
}
|
|
673
|
+
constructor(r, editorService, er, doc) {
|
|
674
|
+
this.r = r;
|
|
675
|
+
this.editorService = editorService;
|
|
676
|
+
this.er = er;
|
|
677
|
+
this.doc = doc;
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* Trigger command from editor header buttons
|
|
681
|
+
* @param command string from toolbar buttons
|
|
682
|
+
*/
|
|
683
|
+
triggerCommand(command) {
|
|
684
|
+
this.execute.emit(command);
|
|
685
|
+
}
|
|
686
|
+
/**
|
|
687
|
+
* highlight editor buttons when cursor moved or positioning
|
|
688
|
+
*/
|
|
689
|
+
triggerButtons() {
|
|
690
|
+
if (!this.showToolbar) {
|
|
691
|
+
return;
|
|
692
|
+
}
|
|
693
|
+
this.buttons.forEach(e => {
|
|
694
|
+
const result = this.doc.queryCommandState(e);
|
|
695
|
+
const elementById = this.doc.getElementById(e + '-' + this.id);
|
|
696
|
+
if (result) {
|
|
697
|
+
this.r.addClass(elementById, 'active');
|
|
698
|
+
}
|
|
699
|
+
else {
|
|
700
|
+
this.r.removeClass(elementById, 'active');
|
|
701
|
+
}
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
/**
|
|
705
|
+
* trigger highlight editor buttons when cursor moved or positioning in block
|
|
706
|
+
*/
|
|
707
|
+
triggerBlocks(nodes) {
|
|
708
|
+
if (!this.showToolbar) {
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
711
|
+
this.linkSelected = nodes.findIndex(x => x.nodeName === 'A') > -1;
|
|
712
|
+
let found = false;
|
|
713
|
+
this.select.forEach(y => {
|
|
714
|
+
const node = nodes.find(x => x.nodeName === y);
|
|
715
|
+
if (node !== undefined && y === node.nodeName) {
|
|
716
|
+
if (found === false) {
|
|
717
|
+
this.block = node.nodeName.toLowerCase();
|
|
718
|
+
found = true;
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
else if (found === false) {
|
|
722
|
+
this.block = 'default';
|
|
723
|
+
}
|
|
724
|
+
});
|
|
725
|
+
found = false;
|
|
726
|
+
if (this._customClasses) {
|
|
727
|
+
this._customClasses.forEach((y, index) => {
|
|
728
|
+
const node = nodes.find(x => {
|
|
729
|
+
if (x instanceof Element) {
|
|
730
|
+
return x.className === y.class;
|
|
731
|
+
}
|
|
732
|
+
});
|
|
733
|
+
if (node !== undefined) {
|
|
734
|
+
if (found === false) {
|
|
735
|
+
this.customClassId = index.toString();
|
|
736
|
+
found = true;
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
else if (found === false) {
|
|
740
|
+
this.customClassId = '-1';
|
|
741
|
+
}
|
|
742
|
+
});
|
|
743
|
+
}
|
|
744
|
+
Object.keys(this.tagMap).map(e => {
|
|
745
|
+
const elementById = this.doc.getElementById(this.tagMap[e] + '-' + this.id);
|
|
746
|
+
const node = nodes.find(x => x.nodeName === e);
|
|
747
|
+
if (node !== undefined && e === node.nodeName) {
|
|
748
|
+
this.r.addClass(elementById, 'active');
|
|
749
|
+
}
|
|
750
|
+
else {
|
|
751
|
+
this.r.removeClass(elementById, 'active');
|
|
752
|
+
}
|
|
753
|
+
});
|
|
754
|
+
this.foreColour = this.doc.queryCommandValue('ForeColor');
|
|
755
|
+
this.fontSize = this.doc.queryCommandValue('FontSize');
|
|
756
|
+
this.fontName = this.doc.queryCommandValue('FontName').replace(/"/g, '');
|
|
757
|
+
this.backColor = this.doc.queryCommandValue('backColor');
|
|
758
|
+
}
|
|
759
|
+
/**
|
|
760
|
+
* insert URL link
|
|
761
|
+
*/
|
|
762
|
+
insertUrl() {
|
|
763
|
+
let url = 'https:\/\/';
|
|
764
|
+
const selection = this.editorService.savedSelection;
|
|
765
|
+
if (selection && selection.commonAncestorContainer.parentElement.nodeName === 'A') {
|
|
766
|
+
const parent = selection.commonAncestorContainer.parentElement;
|
|
767
|
+
if (parent.href !== '') {
|
|
768
|
+
url = parent.href;
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
url = prompt('Insert URL link', url);
|
|
772
|
+
if (url && url !== '' && url !== 'https://') {
|
|
773
|
+
this.editorService.createLink(url);
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
/**
|
|
777
|
+
* insert Video link
|
|
778
|
+
*/
|
|
779
|
+
insertVideo() {
|
|
780
|
+
this.execute.emit('');
|
|
781
|
+
const url = prompt('Insert Video link', `https://`);
|
|
782
|
+
if (url && url !== '' && url !== `https://`) {
|
|
783
|
+
this.editorService.insertVideo(url);
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
/** insert color */
|
|
787
|
+
insertColor(color, where) {
|
|
788
|
+
this.editorService.insertColor(color, where);
|
|
789
|
+
this.execute.emit('');
|
|
790
|
+
}
|
|
791
|
+
/**
|
|
792
|
+
* set font Name/family
|
|
793
|
+
* @param foreColor string
|
|
794
|
+
*/
|
|
795
|
+
setFontName(foreColor) {
|
|
796
|
+
this.editorService.setFontName(foreColor);
|
|
797
|
+
this.execute.emit('');
|
|
798
|
+
}
|
|
799
|
+
/**
|
|
800
|
+
* set font Size
|
|
801
|
+
* @param fontSize string
|
|
802
|
+
*/
|
|
803
|
+
setFontSize(fontSize) {
|
|
804
|
+
this.editorService.setFontSize(fontSize);
|
|
805
|
+
this.execute.emit('');
|
|
806
|
+
}
|
|
807
|
+
/**
|
|
808
|
+
* toggle editor mode (WYSIWYG or SOURCE)
|
|
809
|
+
* @param m boolean
|
|
810
|
+
*/
|
|
811
|
+
setEditorMode(m) {
|
|
812
|
+
const toggleEditorModeButton = this.doc.getElementById('toggleEditorMode' + '-' + this.id);
|
|
813
|
+
if (m) {
|
|
814
|
+
this.r.addClass(toggleEditorModeButton, 'active');
|
|
815
|
+
}
|
|
816
|
+
else {
|
|
817
|
+
this.r.removeClass(toggleEditorModeButton, 'active');
|
|
818
|
+
}
|
|
819
|
+
this.htmlMode = m;
|
|
820
|
+
}
|
|
821
|
+
/**
|
|
822
|
+
* Upload image when file is selected.
|
|
823
|
+
*/
|
|
824
|
+
onFileChanged(event) {
|
|
825
|
+
const file = event.target.files[0];
|
|
826
|
+
if (file.type.includes('image/')) {
|
|
827
|
+
if (this.upload) {
|
|
828
|
+
this.upload(file).subscribe((response) => this.watchUploadImage(response, event));
|
|
829
|
+
}
|
|
830
|
+
else if (this.uploadUrl) {
|
|
831
|
+
this.editorService.uploadImage(file).subscribe((response) => this.watchUploadImage(response, event));
|
|
832
|
+
}
|
|
833
|
+
else {
|
|
834
|
+
const reader = new FileReader();
|
|
835
|
+
reader.onload = (e) => {
|
|
836
|
+
const fr = e.currentTarget;
|
|
837
|
+
this.editorService.insertImage(fr.result.toString());
|
|
838
|
+
};
|
|
839
|
+
reader.readAsDataURL(file);
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
watchUploadImage(response, event) {
|
|
844
|
+
const { imageUrl } = response.body;
|
|
845
|
+
this.editorService.insertImage(imageUrl);
|
|
846
|
+
event.srcElement.value = null;
|
|
847
|
+
}
|
|
848
|
+
/**
|
|
849
|
+
* Set custom class
|
|
850
|
+
*/
|
|
851
|
+
setCustomClass(classId) {
|
|
852
|
+
if (classId === '-1') {
|
|
853
|
+
this.execute.emit('clear');
|
|
854
|
+
}
|
|
855
|
+
else {
|
|
856
|
+
this.editorService.createCustomClass(this._customClasses[+classId]);
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
isButtonHidden(name) {
|
|
860
|
+
if (!name) {
|
|
861
|
+
return false;
|
|
862
|
+
}
|
|
863
|
+
if (!(this.hiddenButtons instanceof Array)) {
|
|
864
|
+
return false;
|
|
865
|
+
}
|
|
866
|
+
let result;
|
|
867
|
+
for (const arr of this.hiddenButtons) {
|
|
868
|
+
if (arr instanceof Array) {
|
|
869
|
+
result = arr.find(item => item === name);
|
|
870
|
+
}
|
|
871
|
+
if (result) {
|
|
872
|
+
break;
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
return result !== undefined;
|
|
876
|
+
}
|
|
877
|
+
focus() {
|
|
878
|
+
this.execute.emit('focus');
|
|
879
|
+
console.log('focused');
|
|
880
|
+
}
|
|
881
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.13", ngImport: i0, type: AeToolbarComponent, deps: [{ token: i0.Renderer2 }, { token: AngularEditorService }, { token: i0.ElementRef }, { token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Component });
|
|
882
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.13", type: AeToolbarComponent, isStandalone: false, selector: "angular-editor-toolbar, ae-toolbar, div[aeToolbar]", inputs: { id: "id", uploadUrl: "uploadUrl", upload: "upload", showToolbar: "showToolbar", fonts: "fonts", customClasses: "customClasses", defaultFontName: "defaultFontName", defaultFontSize: "defaultFontSize", hiddenButtons: "hiddenButtons" }, outputs: { execute: "execute" }, viewQueries: [{ propertyName: "myInputFile", first: true, predicate: ["fileInput"], descendants: true, static: true }], ngImport: i0, template: "<div class=\"angular-editor-toolbar\" *ngIf=\"showToolbar\">\n <div aeToolbarSet>\n <button aeButton title=\"Undo\" iconName=\"undo\" (click)=\"triggerCommand('undo')\" [hidden]=\"isButtonHidden('undo')\">\n </button>\n <button aeButton title=\"Redo\" iconName=\"redo\" (click)=\"triggerCommand('redo')\"\n [hidden]=\"isButtonHidden('redo')\">\n </button>\n </div>\n <div aeToolbarSet>\n <button [id]=\"'bold-'+id\" aeButton title=\"Bold\" iconName=\"bold\" (click)=\"triggerCommand('bold')\"\n [disabled]=\"htmlMode\" [hidden]=\"isButtonHidden('bold')\">\n </button>\n <button [id]=\"'italic-'+id\" aeButton iconName=\"italic\" title=\"Italic\" (click)=\"triggerCommand('italic')\"\n [disabled]=\"htmlMode\" [hidden]=\"isButtonHidden('italic')\">\n </button>\n <button [id]=\"'underline-'+id\" aeButton title=\"Underline\" iconName=\"underline\"\n (click)=\"triggerCommand('underline')\" [disabled]=\"htmlMode\" [hidden]=\"isButtonHidden('underline')\">\n </button>\n <button [id]=\"'strikeThrough-'+id\" aeButton iconName=\"strikeThrough\" title=\"Strikethrough\"\n (click)=\"triggerCommand('strikeThrough')\" [disabled]=\"htmlMode\"\n [hidden]=\"isButtonHidden('strikeThrough')\">\n </button>\n <button [id]=\"'subscript-'+id\" aeButton title=\"Subscript\" iconName=\"subscript\"\n (click)=\"triggerCommand('subscript')\" [disabled]=\"htmlMode\" [hidden]=\"isButtonHidden('subscript')\">\n </button>\n <button [id]=\"'superscript-'+id\" aeButton iconName=\"superscript\" title=\"Superscript\"\n (click)=\"triggerCommand('superscript')\" [disabled]=\"htmlMode\"\n [hidden]=\"isButtonHidden('superscript')\">\n </button>\n </div>\n <div aeToolbarSet>\n <button [id]=\"'justifyLeft-'+id\" aeButton iconName=\"justifyLeft\" title=\"Justify Left\"\n (click)=\"triggerCommand('justifyLeft')\" [disabled]=\"htmlMode\"\n [hidden]=\"isButtonHidden('justifyLeft')\">\n </button>\n <button [id]=\"'justifyCenter-'+id\" aeButton iconName=\"justifyCenter\" title=\"Justify Center\"\n (click)=\"triggerCommand('justifyCenter')\" [disabled]=\"htmlMode\"\n [hidden]=\"isButtonHidden('justifyCenter')\">\n </button>\n <button [id]=\"'justifyRight-'+id\" aeButton iconName=\"justifyRight\" title=\"Justify Right\"\n (click)=\"triggerCommand('justifyRight')\" [disabled]=\"htmlMode\"\n [hidden]=\"isButtonHidden('justifyRight')\">\n </button>\n <button [id]=\"'justifyFull-'+id\" aeButton iconName=\"justifyFull\" title=\"Justify Full\"\n (click)=\"triggerCommand('justifyFull')\" [disabled]=\"htmlMode\"\n [hidden]=\"isButtonHidden('justifyFull')\">\n </button>\n </div>\n <div aeToolbarSet>\n <button [id]=\"'indent-'+id\" aeButton iconName=\"indent\" title=\"Indent\"\n (click)=\"triggerCommand('indent')\"\n [disabled]=\"htmlMode\" [hidden]=\"isButtonHidden('indent')\">\n </button>\n <button [id]=\"'outdent-'+id\" aeButton iconName=\"outdent\" title=\"Outdent\"\n (click)=\"triggerCommand('outdent')\"\n [disabled]=\"htmlMode\" [hidden]=\"isButtonHidden('outdent')\">\n </button>\n </div>\n <div aeToolbarSet>\n <button [id]=\"'insertUnorderedList-'+id\" aeButton iconName=\"unorderedList\" title=\"Unordered List\"\n (click)=\"triggerCommand('insertUnorderedList')\" [disabled]=\"htmlMode\"\n [hidden]=\"isButtonHidden('insertUnorderedList')\">\n </button>\n <button [id]=\"'insertOrderedList-'+id\" aeButton iconName=\"orderedList\" title=\"Ordered List\"\n (click)=\"triggerCommand('insertOrderedList')\" [disabled]=\"htmlMode\"\n [hidden]=\"isButtonHidden('insertOrderedList')\">\n </button>\n </div>\n <div aeToolbarSet>\n <ae-select class=\"select-heading\" [options]=\"headings\"\n [(ngModel)]=\"block\"\n (change)=\"triggerCommand(block)\"\n [disabled]=\"htmlMode\"\n [hidden]=\"isButtonHidden('heading')\"\n tabindex=\"-1\"></ae-select>\n </div>\n <div aeToolbarSet>\n <ae-select class=\"select-font\" [options]=\"fonts\"\n [(ngModel)]=\"fontName\"\n (change)=\"setFontName(fontName)\"\n [disabled]=\"htmlMode\"\n [hidden]=\"isButtonHidden('fontName')\"\n tabindex=\"-1\"></ae-select>\n </div>\n <div aeToolbarSet>\n <ae-select class=\"select-font-size\" [options]=\"fontSizes\"\n [(ngModel)]=\"fontSize\"\n (change)=\"setFontSize(fontSize)\"\n [disabled]=\"htmlMode\"\n [hidden]=\"isButtonHidden('fontSize')\"\n tabindex=\"-1\">\n </ae-select>\n </div>\n <div aeToolbarSet>\n <input\n style=\"display: none\"\n type=\"color\" (change)=\"insertColor(fgInput.value, 'textColor')\"\n #fgInput>\n <button [id]=\"'foregroundColorPicker-'+id\" aeButton iconName=\"textColor\"\n (click)=\"focus(); ; fgInput.click()\"\n title=\"Text Color\"\n [disabled]=\"htmlMode\" [hidden]=\"isButtonHidden('textColor')\">\n </button>\n <input\n style=\"display: none\"\n type=\"color\" (change)=\"insertColor(bgInput.value, 'backgroundColor')\"\n #bgInput>\n <button [id]=\"'backgroundColorPicker-'+id\" aeButton iconName=\"backgroundColor\"\n (click)=\"focus(); ; bgInput.click()\"\n title=\"Background Color\"\n [disabled]=\"htmlMode\" [hidden]=\"isButtonHidden('backgroundColor')\">\n </button>\n </div>\n <div *ngIf=\"_customClasses\" aeToolbarSet>\n <ae-select class=\"select-custom-style\" [options]=\"customClassList\"\n [(ngModel)]=\"customClassId\"\n (change)=\"setCustomClass(customClassId)\"\n [disabled]=\"htmlMode\"\n [hidden]=\"isButtonHidden('customClasses')\"\n tabindex=\"-1\"></ae-select>\n </div>\n <div aeToolbarSet>\n <button [id]=\"'link-'+id\" aeButton iconName=\"link\" (click)=\"insertUrl()\"\n title=\"Insert Link\" [disabled]=\"isLinkButtonDisabled\" [hidden]=\"isButtonHidden('link')\">\n </button>\n <button [id]=\"'unlink-'+id\" aeButton iconName=\"unlink\" (click)=\"triggerCommand('unlink')\"\n title=\"Unlink\" [disabled]=\"htmlMode || !linkSelected\" [hidden]=\"isButtonHidden('unlink')\">\n </button>\n <input\n style=\"display: none\"\n accept=\"image/*\"\n type=\"file\" (change)=\"onFileChanged($event)\"\n #fileInput>\n <button [id]=\"'insertImage-'+id\" aeButton iconName=\"image\" (click)=\"focus(); fileInput.click()\"\n title=\"Insert Image\"\n [disabled]=\"htmlMode\" [hidden]=\"isButtonHidden('insertImage')\">\n </button>\n <button [id]=\"'insertVideo-'+id\" aeButton iconName=\"video\"\n (click)=\"insertVideo()\" title=\"Insert Video\" [disabled]=\"htmlMode\"\n [hidden]=\"isButtonHidden('insertVideo')\">\n </button>\n <button [id]=\"'insertHorizontalRule-'+id\" aeButton iconName=\"horizontalLine\" title=\"Horizontal Line\"\n (click)=\"triggerCommand('insertHorizontalRule')\" [disabled]=\"htmlMode\"\n [hidden]=\"isButtonHidden('insertHorizontalRule')\">\n </button>\n </div>\n <div aeToolbarSet>\n <button [id]=\"'clearFormatting-'+id\" aeButton iconName=\"removeFormat\" title=\"Clear Formatting\"\n class=\"angular-editor-button\"\n (click)=\"triggerCommand('removeFormat')\" [disabled]=\"htmlMode\" [hidden]=\"isButtonHidden('removeFormat')\">\n </button>\n </div>\n <div aeToolbarSet>\n <button [id]=\"'toggleEditorMode-'+id\" aeButton iconName=\"htmlCode\" title=\"HTML Code\"\n (click)=\"triggerCommand('toggleEditorMode')\" [hidden]=\"isButtonHidden('toggleEditorMode')\">\n </button>\n </div>\n <ng-content></ng-content>\n</div>\n", styles: ["a{cursor:pointer}.angular-editor-toolbar{font:100 14px/15px Roboto,Arial,sans-serif;background-color:var(--ae-toolbar-bg-color, #f5f5f5);font-size:.8rem;padding:var(--ae-toolbar-padding, .2rem);border:var(--ae-toolbar-border-radius, 1px solid #ddd);display:flex;flex-wrap:wrap;gap:4px}.select-heading{display:inline-block;width:90px}@supports not (-moz-appearance: none){.select-heading optgroup{font-size:12px;background-color:#f4f4f4;padding:5px}.select-heading option{border:1px solid;background-color:#fff}}.select-heading:disabled{background-color:#f5f5f5;pointer-events:none;cursor:not-allowed}.select-heading:hover{cursor:pointer;background-color:#f1f1f1;transition:.2s ease}.select-font{display:inline-block;width:90px}@supports not (-moz-appearance: none){.select-font optgroup{font-size:12px;background-color:#f4f4f4;padding:5px}.select-font option{border:1px solid;background-color:#fff}}.select-font:disabled{background-color:#f5f5f5;pointer-events:none;cursor:not-allowed}.select-font:hover{cursor:pointer;background-color:#f1f1f1;transition:.2s ease}.select-font-size{display:inline-block;width:50px}@supports not (-moz-appearance: none){.select-font-size optgroup{font-size:12px;background-color:#f4f4f4;padding:5px}.select-font-size option{border:1px solid;background-color:#fff}.select-font-size .size1{font-size:10px}.select-font-size .size2{font-size:12px}.select-font-size .size3{font-size:14px}.select-font-size .size4{font-size:16px}.select-font-size .size5{font-size:18px}.select-font-size .size6{font-size:20px}.select-font-size .size7{font-size:22px}}.select-font-size:disabled{background-color:#f5f5f5;pointer-events:none;cursor:not-allowed}.select-font-size:hover{cursor:pointer;background-color:#f1f1f1;transition:.2s ease}.select-custom-style{display:inline-block;width:90px}@supports not (-moz-appearance: none){.select-custom-style optgroup{font-size:12px;background-color:#f4f4f4;padding:5px}.select-custom-style option{border:1px solid;background-color:#fff}}.select-custom-style:disabled{background-color:#f5f5f5;pointer-events:none;cursor:not-allowed}.select-custom-style:hover{cursor:pointer;background-color:#f1f1f1;transition:.2s ease}.color-label{position:relative;cursor:pointer}.background{font-size:smaller;background:#1b1b1b;color:#fff;padding:3px}.foreground :after{position:absolute;content:\"\";inset:auto auto -3px -1px;width:15px;height:2px;z-index:0;background:#1b1b1b}.default{font-size:16px}h1{font-size:24px}h2{font-size:20px}h3{font-size:16px}h4{font-size:15px}h5{font-size:14px}h6{font-size:13px}div,pre{font-size:12px}\n"], dependencies: [{ kind: "directive", type: i1$1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i3.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i3.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "component", type: AeSelectComponent, selector: "ae-select", inputs: ["options", "hidden"], outputs: ["change"] }, { kind: "component", type: AeButtonComponent, selector: "ae-button, button[aeButton]", inputs: ["iconName"] }, { kind: "component", type: AeToolbarSetComponent, selector: "ae-toolbar-set, [aeToolbarSet]" }] });
|
|
883
|
+
}
|
|
884
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.13", ngImport: i0, type: AeToolbarComponent, decorators: [{
|
|
885
|
+
type: Component,
|
|
886
|
+
args: [{ selector: 'angular-editor-toolbar, ae-toolbar, div[aeToolbar]', standalone: false, template: "<div class=\"angular-editor-toolbar\" *ngIf=\"showToolbar\">\n <div aeToolbarSet>\n <button aeButton title=\"Undo\" iconName=\"undo\" (click)=\"triggerCommand('undo')\" [hidden]=\"isButtonHidden('undo')\">\n </button>\n <button aeButton title=\"Redo\" iconName=\"redo\" (click)=\"triggerCommand('redo')\"\n [hidden]=\"isButtonHidden('redo')\">\n </button>\n </div>\n <div aeToolbarSet>\n <button [id]=\"'bold-'+id\" aeButton title=\"Bold\" iconName=\"bold\" (click)=\"triggerCommand('bold')\"\n [disabled]=\"htmlMode\" [hidden]=\"isButtonHidden('bold')\">\n </button>\n <button [id]=\"'italic-'+id\" aeButton iconName=\"italic\" title=\"Italic\" (click)=\"triggerCommand('italic')\"\n [disabled]=\"htmlMode\" [hidden]=\"isButtonHidden('italic')\">\n </button>\n <button [id]=\"'underline-'+id\" aeButton title=\"Underline\" iconName=\"underline\"\n (click)=\"triggerCommand('underline')\" [disabled]=\"htmlMode\" [hidden]=\"isButtonHidden('underline')\">\n </button>\n <button [id]=\"'strikeThrough-'+id\" aeButton iconName=\"strikeThrough\" title=\"Strikethrough\"\n (click)=\"triggerCommand('strikeThrough')\" [disabled]=\"htmlMode\"\n [hidden]=\"isButtonHidden('strikeThrough')\">\n </button>\n <button [id]=\"'subscript-'+id\" aeButton title=\"Subscript\" iconName=\"subscript\"\n (click)=\"triggerCommand('subscript')\" [disabled]=\"htmlMode\" [hidden]=\"isButtonHidden('subscript')\">\n </button>\n <button [id]=\"'superscript-'+id\" aeButton iconName=\"superscript\" title=\"Superscript\"\n (click)=\"triggerCommand('superscript')\" [disabled]=\"htmlMode\"\n [hidden]=\"isButtonHidden('superscript')\">\n </button>\n </div>\n <div aeToolbarSet>\n <button [id]=\"'justifyLeft-'+id\" aeButton iconName=\"justifyLeft\" title=\"Justify Left\"\n (click)=\"triggerCommand('justifyLeft')\" [disabled]=\"htmlMode\"\n [hidden]=\"isButtonHidden('justifyLeft')\">\n </button>\n <button [id]=\"'justifyCenter-'+id\" aeButton iconName=\"justifyCenter\" title=\"Justify Center\"\n (click)=\"triggerCommand('justifyCenter')\" [disabled]=\"htmlMode\"\n [hidden]=\"isButtonHidden('justifyCenter')\">\n </button>\n <button [id]=\"'justifyRight-'+id\" aeButton iconName=\"justifyRight\" title=\"Justify Right\"\n (click)=\"triggerCommand('justifyRight')\" [disabled]=\"htmlMode\"\n [hidden]=\"isButtonHidden('justifyRight')\">\n </button>\n <button [id]=\"'justifyFull-'+id\" aeButton iconName=\"justifyFull\" title=\"Justify Full\"\n (click)=\"triggerCommand('justifyFull')\" [disabled]=\"htmlMode\"\n [hidden]=\"isButtonHidden('justifyFull')\">\n </button>\n </div>\n <div aeToolbarSet>\n <button [id]=\"'indent-'+id\" aeButton iconName=\"indent\" title=\"Indent\"\n (click)=\"triggerCommand('indent')\"\n [disabled]=\"htmlMode\" [hidden]=\"isButtonHidden('indent')\">\n </button>\n <button [id]=\"'outdent-'+id\" aeButton iconName=\"outdent\" title=\"Outdent\"\n (click)=\"triggerCommand('outdent')\"\n [disabled]=\"htmlMode\" [hidden]=\"isButtonHidden('outdent')\">\n </button>\n </div>\n <div aeToolbarSet>\n <button [id]=\"'insertUnorderedList-'+id\" aeButton iconName=\"unorderedList\" title=\"Unordered List\"\n (click)=\"triggerCommand('insertUnorderedList')\" [disabled]=\"htmlMode\"\n [hidden]=\"isButtonHidden('insertUnorderedList')\">\n </button>\n <button [id]=\"'insertOrderedList-'+id\" aeButton iconName=\"orderedList\" title=\"Ordered List\"\n (click)=\"triggerCommand('insertOrderedList')\" [disabled]=\"htmlMode\"\n [hidden]=\"isButtonHidden('insertOrderedList')\">\n </button>\n </div>\n <div aeToolbarSet>\n <ae-select class=\"select-heading\" [options]=\"headings\"\n [(ngModel)]=\"block\"\n (change)=\"triggerCommand(block)\"\n [disabled]=\"htmlMode\"\n [hidden]=\"isButtonHidden('heading')\"\n tabindex=\"-1\"></ae-select>\n </div>\n <div aeToolbarSet>\n <ae-select class=\"select-font\" [options]=\"fonts\"\n [(ngModel)]=\"fontName\"\n (change)=\"setFontName(fontName)\"\n [disabled]=\"htmlMode\"\n [hidden]=\"isButtonHidden('fontName')\"\n tabindex=\"-1\"></ae-select>\n </div>\n <div aeToolbarSet>\n <ae-select class=\"select-font-size\" [options]=\"fontSizes\"\n [(ngModel)]=\"fontSize\"\n (change)=\"setFontSize(fontSize)\"\n [disabled]=\"htmlMode\"\n [hidden]=\"isButtonHidden('fontSize')\"\n tabindex=\"-1\">\n </ae-select>\n </div>\n <div aeToolbarSet>\n <input\n style=\"display: none\"\n type=\"color\" (change)=\"insertColor(fgInput.value, 'textColor')\"\n #fgInput>\n <button [id]=\"'foregroundColorPicker-'+id\" aeButton iconName=\"textColor\"\n (click)=\"focus(); ; fgInput.click()\"\n title=\"Text Color\"\n [disabled]=\"htmlMode\" [hidden]=\"isButtonHidden('textColor')\">\n </button>\n <input\n style=\"display: none\"\n type=\"color\" (change)=\"insertColor(bgInput.value, 'backgroundColor')\"\n #bgInput>\n <button [id]=\"'backgroundColorPicker-'+id\" aeButton iconName=\"backgroundColor\"\n (click)=\"focus(); ; bgInput.click()\"\n title=\"Background Color\"\n [disabled]=\"htmlMode\" [hidden]=\"isButtonHidden('backgroundColor')\">\n </button>\n </div>\n <div *ngIf=\"_customClasses\" aeToolbarSet>\n <ae-select class=\"select-custom-style\" [options]=\"customClassList\"\n [(ngModel)]=\"customClassId\"\n (change)=\"setCustomClass(customClassId)\"\n [disabled]=\"htmlMode\"\n [hidden]=\"isButtonHidden('customClasses')\"\n tabindex=\"-1\"></ae-select>\n </div>\n <div aeToolbarSet>\n <button [id]=\"'link-'+id\" aeButton iconName=\"link\" (click)=\"insertUrl()\"\n title=\"Insert Link\" [disabled]=\"isLinkButtonDisabled\" [hidden]=\"isButtonHidden('link')\">\n </button>\n <button [id]=\"'unlink-'+id\" aeButton iconName=\"unlink\" (click)=\"triggerCommand('unlink')\"\n title=\"Unlink\" [disabled]=\"htmlMode || !linkSelected\" [hidden]=\"isButtonHidden('unlink')\">\n </button>\n <input\n style=\"display: none\"\n accept=\"image/*\"\n type=\"file\" (change)=\"onFileChanged($event)\"\n #fileInput>\n <button [id]=\"'insertImage-'+id\" aeButton iconName=\"image\" (click)=\"focus(); fileInput.click()\"\n title=\"Insert Image\"\n [disabled]=\"htmlMode\" [hidden]=\"isButtonHidden('insertImage')\">\n </button>\n <button [id]=\"'insertVideo-'+id\" aeButton iconName=\"video\"\n (click)=\"insertVideo()\" title=\"Insert Video\" [disabled]=\"htmlMode\"\n [hidden]=\"isButtonHidden('insertVideo')\">\n </button>\n <button [id]=\"'insertHorizontalRule-'+id\" aeButton iconName=\"horizontalLine\" title=\"Horizontal Line\"\n (click)=\"triggerCommand('insertHorizontalRule')\" [disabled]=\"htmlMode\"\n [hidden]=\"isButtonHidden('insertHorizontalRule')\">\n </button>\n </div>\n <div aeToolbarSet>\n <button [id]=\"'clearFormatting-'+id\" aeButton iconName=\"removeFormat\" title=\"Clear Formatting\"\n class=\"angular-editor-button\"\n (click)=\"triggerCommand('removeFormat')\" [disabled]=\"htmlMode\" [hidden]=\"isButtonHidden('removeFormat')\">\n </button>\n </div>\n <div aeToolbarSet>\n <button [id]=\"'toggleEditorMode-'+id\" aeButton iconName=\"htmlCode\" title=\"HTML Code\"\n (click)=\"triggerCommand('toggleEditorMode')\" [hidden]=\"isButtonHidden('toggleEditorMode')\">\n </button>\n </div>\n <ng-content></ng-content>\n</div>\n", styles: ["a{cursor:pointer}.angular-editor-toolbar{font:100 14px/15px Roboto,Arial,sans-serif;background-color:var(--ae-toolbar-bg-color, #f5f5f5);font-size:.8rem;padding:var(--ae-toolbar-padding, .2rem);border:var(--ae-toolbar-border-radius, 1px solid #ddd);display:flex;flex-wrap:wrap;gap:4px}.select-heading{display:inline-block;width:90px}@supports not (-moz-appearance: none){.select-heading optgroup{font-size:12px;background-color:#f4f4f4;padding:5px}.select-heading option{border:1px solid;background-color:#fff}}.select-heading:disabled{background-color:#f5f5f5;pointer-events:none;cursor:not-allowed}.select-heading:hover{cursor:pointer;background-color:#f1f1f1;transition:.2s ease}.select-font{display:inline-block;width:90px}@supports not (-moz-appearance: none){.select-font optgroup{font-size:12px;background-color:#f4f4f4;padding:5px}.select-font option{border:1px solid;background-color:#fff}}.select-font:disabled{background-color:#f5f5f5;pointer-events:none;cursor:not-allowed}.select-font:hover{cursor:pointer;background-color:#f1f1f1;transition:.2s ease}.select-font-size{display:inline-block;width:50px}@supports not (-moz-appearance: none){.select-font-size optgroup{font-size:12px;background-color:#f4f4f4;padding:5px}.select-font-size option{border:1px solid;background-color:#fff}.select-font-size .size1{font-size:10px}.select-font-size .size2{font-size:12px}.select-font-size .size3{font-size:14px}.select-font-size .size4{font-size:16px}.select-font-size .size5{font-size:18px}.select-font-size .size6{font-size:20px}.select-font-size .size7{font-size:22px}}.select-font-size:disabled{background-color:#f5f5f5;pointer-events:none;cursor:not-allowed}.select-font-size:hover{cursor:pointer;background-color:#f1f1f1;transition:.2s ease}.select-custom-style{display:inline-block;width:90px}@supports not (-moz-appearance: none){.select-custom-style optgroup{font-size:12px;background-color:#f4f4f4;padding:5px}.select-custom-style option{border:1px solid;background-color:#fff}}.select-custom-style:disabled{background-color:#f5f5f5;pointer-events:none;cursor:not-allowed}.select-custom-style:hover{cursor:pointer;background-color:#f1f1f1;transition:.2s ease}.color-label{position:relative;cursor:pointer}.background{font-size:smaller;background:#1b1b1b;color:#fff;padding:3px}.foreground :after{position:absolute;content:\"\";inset:auto auto -3px -1px;width:15px;height:2px;z-index:0;background:#1b1b1b}.default{font-size:16px}h1{font-size:24px}h2{font-size:20px}h3{font-size:16px}h4{font-size:15px}h5{font-size:14px}h6{font-size:13px}div,pre{font-size:12px}\n"] }]
|
|
887
|
+
}], ctorParameters: () => [{ type: i0.Renderer2 }, { type: AngularEditorService }, { type: i0.ElementRef }, { type: undefined, decorators: [{
|
|
888
|
+
type: Inject,
|
|
889
|
+
args: [DOCUMENT]
|
|
890
|
+
}] }], propDecorators: { id: [{
|
|
891
|
+
type: Input
|
|
892
|
+
}], uploadUrl: [{
|
|
893
|
+
type: Input
|
|
894
|
+
}], upload: [{
|
|
895
|
+
type: Input
|
|
896
|
+
}], showToolbar: [{
|
|
897
|
+
type: Input
|
|
898
|
+
}], fonts: [{
|
|
899
|
+
type: Input
|
|
900
|
+
}], customClasses: [{
|
|
901
|
+
type: Input
|
|
902
|
+
}], defaultFontName: [{
|
|
903
|
+
type: Input
|
|
904
|
+
}], defaultFontSize: [{
|
|
905
|
+
type: Input
|
|
906
|
+
}], hiddenButtons: [{
|
|
907
|
+
type: Input
|
|
908
|
+
}], execute: [{
|
|
909
|
+
type: Output
|
|
910
|
+
}], myInputFile: [{
|
|
911
|
+
type: ViewChild,
|
|
912
|
+
args: ['fileInput', { static: true }]
|
|
913
|
+
}] } });
|
|
914
|
+
|
|
915
|
+
class AngularEditorComponent {
|
|
916
|
+
r;
|
|
917
|
+
editorService;
|
|
918
|
+
doc;
|
|
919
|
+
sanitizer;
|
|
920
|
+
cdRef;
|
|
921
|
+
autoFocus;
|
|
922
|
+
onChange;
|
|
923
|
+
onTouched;
|
|
924
|
+
modeVisual = true;
|
|
925
|
+
showPlaceholder = false;
|
|
926
|
+
disabled = false;
|
|
927
|
+
focused = false;
|
|
928
|
+
touched = false;
|
|
929
|
+
changed = false;
|
|
930
|
+
focusInstance;
|
|
931
|
+
blurInstance;
|
|
932
|
+
id = '';
|
|
933
|
+
config = angularEditorConfig;
|
|
934
|
+
placeholder = '';
|
|
935
|
+
tabIndex;
|
|
936
|
+
html;
|
|
937
|
+
textArea;
|
|
938
|
+
editorWrapper;
|
|
939
|
+
editorToolbar;
|
|
940
|
+
customButtonsTemplateRef;
|
|
941
|
+
executeCommandFn = this.executeCommand.bind(this);
|
|
942
|
+
viewMode = new EventEmitter();
|
|
943
|
+
/** emits `blur` event when focused out from the textarea */
|
|
944
|
+
// eslint-disable-next-line @angular-eslint/no-output-native, @angular-eslint/no-output-rename
|
|
945
|
+
blurEvent = new EventEmitter();
|
|
946
|
+
/** emits `focus` event when focused in to the textarea */
|
|
947
|
+
// eslint-disable-next-line @angular-eslint/no-output-rename, @angular-eslint/no-output-native
|
|
948
|
+
focusEvent = new EventEmitter();
|
|
949
|
+
tabindex = -1;
|
|
950
|
+
onFocus() {
|
|
951
|
+
this.focus();
|
|
952
|
+
}
|
|
953
|
+
constructor(r, editorService, doc, sanitizer, cdRef, defaultTabIndex, autoFocus) {
|
|
954
|
+
this.r = r;
|
|
955
|
+
this.editorService = editorService;
|
|
956
|
+
this.doc = doc;
|
|
957
|
+
this.sanitizer = sanitizer;
|
|
958
|
+
this.cdRef = cdRef;
|
|
959
|
+
this.autoFocus = autoFocus;
|
|
960
|
+
const parsedTabIndex = Number(defaultTabIndex);
|
|
961
|
+
this.tabIndex = (parsedTabIndex || parsedTabIndex === 0) ? parsedTabIndex : null;
|
|
962
|
+
}
|
|
963
|
+
ngOnInit() {
|
|
964
|
+
this.config.toolbarPosition = this.config.toolbarPosition ? this.config.toolbarPosition : angularEditorConfig.toolbarPosition;
|
|
965
|
+
}
|
|
966
|
+
ngAfterViewInit() {
|
|
967
|
+
if (isDefined(this.autoFocus)) {
|
|
968
|
+
this.focus();
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
onPaste(event) {
|
|
972
|
+
if (this.config.rawPaste) {
|
|
973
|
+
event.preventDefault();
|
|
974
|
+
const text = event.clipboardData.getData('text/plain');
|
|
975
|
+
document.execCommand('insertHTML', false, text);
|
|
976
|
+
return text;
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
/**
|
|
980
|
+
* Executed command from editor header buttons
|
|
981
|
+
* @param command string from triggerCommand
|
|
982
|
+
* @param value
|
|
983
|
+
*/
|
|
984
|
+
executeCommand(command, value) {
|
|
985
|
+
this.focus();
|
|
986
|
+
if (command === 'focus') {
|
|
987
|
+
return;
|
|
988
|
+
}
|
|
989
|
+
if (command === 'toggleEditorMode') {
|
|
990
|
+
this.toggleEditorMode(this.modeVisual);
|
|
991
|
+
}
|
|
992
|
+
else if (command !== '') {
|
|
993
|
+
if (command === 'clear') {
|
|
994
|
+
this.editorService.removeSelectedElements(this.getCustomTags());
|
|
995
|
+
this.onContentChange(this.textArea.nativeElement);
|
|
996
|
+
}
|
|
997
|
+
else if (command === 'default') {
|
|
998
|
+
this.editorService.removeSelectedElements('h1,h2,h3,h4,h5,h6,p,pre');
|
|
999
|
+
this.onContentChange(this.textArea.nativeElement);
|
|
1000
|
+
}
|
|
1001
|
+
else {
|
|
1002
|
+
this.editorService.executeCommand(command, value);
|
|
1003
|
+
}
|
|
1004
|
+
this.exec();
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
/**
|
|
1008
|
+
* focus event
|
|
1009
|
+
*/
|
|
1010
|
+
onTextAreaFocus(event) {
|
|
1011
|
+
if (this.focused) {
|
|
1012
|
+
event.stopPropagation();
|
|
1013
|
+
return;
|
|
1014
|
+
}
|
|
1015
|
+
this.focused = true;
|
|
1016
|
+
this.focusEvent.emit(event);
|
|
1017
|
+
if (!this.touched || !this.changed) {
|
|
1018
|
+
this.editorService.executeInNextQueueIteration(() => {
|
|
1019
|
+
this.configure();
|
|
1020
|
+
this.touched = true;
|
|
1021
|
+
});
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
/**
|
|
1025
|
+
* @description fires when cursor leaves textarea
|
|
1026
|
+
*/
|
|
1027
|
+
onTextAreaMouseOut(event) {
|
|
1028
|
+
this.editorService.saveSelection();
|
|
1029
|
+
}
|
|
1030
|
+
/**
|
|
1031
|
+
* blur event
|
|
1032
|
+
*/
|
|
1033
|
+
onTextAreaBlur(event) {
|
|
1034
|
+
/**
|
|
1035
|
+
* save selection if focussed out
|
|
1036
|
+
*/
|
|
1037
|
+
this.editorService.executeInNextQueueIteration(this.editorService.saveSelection);
|
|
1038
|
+
if (typeof this.onTouched === 'function') {
|
|
1039
|
+
this.onTouched();
|
|
1040
|
+
}
|
|
1041
|
+
if (event.relatedTarget !== null) {
|
|
1042
|
+
const parent = event.relatedTarget.parentElement;
|
|
1043
|
+
if (!parent.classList.contains('angular-editor-toolbar-set') && !parent.classList.contains('ae-picker')) {
|
|
1044
|
+
this.blurEvent.emit(event);
|
|
1045
|
+
this.focused = false;
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
/**
|
|
1050
|
+
* focus the text area when the editor is focused
|
|
1051
|
+
*/
|
|
1052
|
+
focus() {
|
|
1053
|
+
if (this.modeVisual) {
|
|
1054
|
+
this.textArea.nativeElement.focus();
|
|
1055
|
+
}
|
|
1056
|
+
else {
|
|
1057
|
+
const sourceText = this.doc.getElementById('sourceText' + this.id);
|
|
1058
|
+
sourceText.focus();
|
|
1059
|
+
this.focused = true;
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
/**
|
|
1063
|
+
* Executed from the contenteditable section while the input property changes
|
|
1064
|
+
* @param element html element from contenteditable
|
|
1065
|
+
*/
|
|
1066
|
+
onContentChange(element) {
|
|
1067
|
+
let html = '';
|
|
1068
|
+
if (this.modeVisual) {
|
|
1069
|
+
html = element.innerHTML;
|
|
1070
|
+
}
|
|
1071
|
+
else {
|
|
1072
|
+
html = element.innerText;
|
|
1073
|
+
}
|
|
1074
|
+
if ((!html || html === '<br>')) {
|
|
1075
|
+
html = '';
|
|
1076
|
+
}
|
|
1077
|
+
if (typeof this.onChange === 'function') {
|
|
1078
|
+
this.onChange(this.config.sanitize || this.config.sanitize === undefined ?
|
|
1079
|
+
this.sanitizer.sanitize(SecurityContext.HTML, html) : html);
|
|
1080
|
+
if ((!html) !== this.showPlaceholder) {
|
|
1081
|
+
this.togglePlaceholder(this.showPlaceholder);
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
this.changed = true;
|
|
1085
|
+
}
|
|
1086
|
+
/**
|
|
1087
|
+
* Set the function to be called
|
|
1088
|
+
* when the control receives a change event.
|
|
1089
|
+
*
|
|
1090
|
+
* @param fn a function
|
|
1091
|
+
*/
|
|
1092
|
+
registerOnChange(fn) {
|
|
1093
|
+
this.onChange = e => (e === '<br>' ? fn('') : fn(e));
|
|
1094
|
+
}
|
|
1095
|
+
/**
|
|
1096
|
+
* Set the function to be called
|
|
1097
|
+
* when the control receives a touch event.
|
|
1098
|
+
*
|
|
1099
|
+
* @param fn a function
|
|
1100
|
+
*/
|
|
1101
|
+
registerOnTouched(fn) {
|
|
1102
|
+
this.onTouched = fn;
|
|
1103
|
+
}
|
|
1104
|
+
/**
|
|
1105
|
+
* Write a new value to the element.
|
|
1106
|
+
*
|
|
1107
|
+
* @param value value to be executed when there is a change in contenteditable
|
|
1108
|
+
*/
|
|
1109
|
+
writeValue(value) {
|
|
1110
|
+
if ((!value || value === '<br>' || value === '') !== this.showPlaceholder) {
|
|
1111
|
+
this.togglePlaceholder(this.showPlaceholder);
|
|
1112
|
+
}
|
|
1113
|
+
if (value === undefined || value === '' || value === '<br>') {
|
|
1114
|
+
value = null;
|
|
1115
|
+
}
|
|
1116
|
+
this.refreshView(value);
|
|
1117
|
+
}
|
|
1118
|
+
/**
|
|
1119
|
+
* refresh view/HTML of the editor
|
|
1120
|
+
*
|
|
1121
|
+
* @param value html string from the editor
|
|
1122
|
+
*/
|
|
1123
|
+
refreshView(value) {
|
|
1124
|
+
const normalizedValue = value === null ? '' : value;
|
|
1125
|
+
this.r.setProperty(this.textArea.nativeElement, 'innerHTML', normalizedValue);
|
|
1126
|
+
return;
|
|
1127
|
+
}
|
|
1128
|
+
/**
|
|
1129
|
+
* toggles placeholder based on input string
|
|
1130
|
+
*
|
|
1131
|
+
* @param value A HTML string from the editor
|
|
1132
|
+
*/
|
|
1133
|
+
togglePlaceholder(value) {
|
|
1134
|
+
if (!value) {
|
|
1135
|
+
this.r.addClass(this.editorWrapper.nativeElement, 'show-placeholder');
|
|
1136
|
+
this.showPlaceholder = true;
|
|
1137
|
+
}
|
|
1138
|
+
else {
|
|
1139
|
+
this.r.removeClass(this.editorWrapper.nativeElement, 'show-placeholder');
|
|
1140
|
+
this.showPlaceholder = false;
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
/**
|
|
1144
|
+
* Implements disabled state for this element
|
|
1145
|
+
*
|
|
1146
|
+
* @param isDisabled Disabled flag
|
|
1147
|
+
*/
|
|
1148
|
+
setDisabledState(isDisabled) {
|
|
1149
|
+
const div = this.textArea.nativeElement;
|
|
1150
|
+
const action = isDisabled ? 'addClass' : 'removeClass';
|
|
1151
|
+
this.r[action](div, 'disabled');
|
|
1152
|
+
this.disabled = isDisabled;
|
|
1153
|
+
}
|
|
1154
|
+
/**
|
|
1155
|
+
* toggles editor mode based on bToSource bool
|
|
1156
|
+
*
|
|
1157
|
+
* @param bToSource A boolean value from the editor
|
|
1158
|
+
*/
|
|
1159
|
+
toggleEditorMode(bToSource) {
|
|
1160
|
+
let oContent;
|
|
1161
|
+
const editableElement = this.textArea.nativeElement;
|
|
1162
|
+
if (bToSource) {
|
|
1163
|
+
oContent = this.r.createText(editableElement.innerHTML);
|
|
1164
|
+
this.r.setProperty(editableElement, 'innerHTML', '');
|
|
1165
|
+
this.r.setProperty(editableElement, 'contentEditable', false);
|
|
1166
|
+
const oPre = this.r.createElement('pre');
|
|
1167
|
+
this.r.setStyle(oPre, 'margin', '0');
|
|
1168
|
+
this.r.setStyle(oPre, 'outline', 'none');
|
|
1169
|
+
const oCode = this.r.createElement('code');
|
|
1170
|
+
this.r.setProperty(oCode, 'id', 'sourceText' + this.id);
|
|
1171
|
+
this.r.setStyle(oCode, 'display', 'block');
|
|
1172
|
+
this.r.setStyle(oCode, 'white-space', 'pre-wrap');
|
|
1173
|
+
this.r.setStyle(oCode, 'word-break', 'keep-all');
|
|
1174
|
+
this.r.setStyle(oCode, 'outline', 'none');
|
|
1175
|
+
this.r.setStyle(oCode, 'margin', '0');
|
|
1176
|
+
this.r.setStyle(oCode, 'background-color', '#fff5b9');
|
|
1177
|
+
this.r.setProperty(oCode, 'contentEditable', true);
|
|
1178
|
+
this.r.appendChild(oCode, oContent);
|
|
1179
|
+
this.focusInstance = this.r.listen(oCode, 'focus', (event) => this.onTextAreaFocus(event));
|
|
1180
|
+
this.blurInstance = this.r.listen(oCode, 'blur', (event) => this.onTextAreaBlur(event));
|
|
1181
|
+
this.r.appendChild(oPre, oCode);
|
|
1182
|
+
this.r.appendChild(editableElement, oPre);
|
|
1183
|
+
// ToDo move to service
|
|
1184
|
+
this.doc.execCommand('defaultParagraphSeparator', false, 'div');
|
|
1185
|
+
this.modeVisual = false;
|
|
1186
|
+
this.viewMode.emit(false);
|
|
1187
|
+
oCode.focus();
|
|
1188
|
+
}
|
|
1189
|
+
else {
|
|
1190
|
+
if (this.doc.querySelectorAll) {
|
|
1191
|
+
this.r.setProperty(editableElement, 'innerHTML', editableElement.innerText);
|
|
1192
|
+
}
|
|
1193
|
+
else {
|
|
1194
|
+
oContent = this.doc.createRange();
|
|
1195
|
+
oContent.selectNodeContents(editableElement.firstChild);
|
|
1196
|
+
this.r.setProperty(editableElement, 'innerHTML', oContent.toString());
|
|
1197
|
+
}
|
|
1198
|
+
this.r.setProperty(editableElement, 'contentEditable', true);
|
|
1199
|
+
this.modeVisual = true;
|
|
1200
|
+
this.viewMode.emit(true);
|
|
1201
|
+
this.onContentChange(editableElement);
|
|
1202
|
+
editableElement.focus();
|
|
1203
|
+
}
|
|
1204
|
+
this.editorToolbar.setEditorMode(!this.modeVisual);
|
|
1205
|
+
}
|
|
1206
|
+
/**
|
|
1207
|
+
* toggles editor buttons when cursor moved or positioning
|
|
1208
|
+
*
|
|
1209
|
+
* Send a node array from the contentEditable of the editor
|
|
1210
|
+
*/
|
|
1211
|
+
exec() {
|
|
1212
|
+
this.editorToolbar.triggerButtons();
|
|
1213
|
+
let userSelection;
|
|
1214
|
+
if (this.doc.getSelection) {
|
|
1215
|
+
userSelection = this.doc.getSelection();
|
|
1216
|
+
this.editorService.executeInNextQueueIteration(this.editorService.saveSelection);
|
|
1217
|
+
}
|
|
1218
|
+
let a = userSelection.focusNode;
|
|
1219
|
+
const els = [];
|
|
1220
|
+
while (a && a.id !== 'editor') {
|
|
1221
|
+
els.unshift(a);
|
|
1222
|
+
a = a.parentNode;
|
|
1223
|
+
}
|
|
1224
|
+
this.editorToolbar.triggerBlocks(els);
|
|
1225
|
+
}
|
|
1226
|
+
configure() {
|
|
1227
|
+
this.editorService.uploadUrl = this.config.uploadUrl;
|
|
1228
|
+
this.editorService.uploadWithCredentials = this.config.uploadWithCredentials;
|
|
1229
|
+
if (this.config.defaultParagraphSeparator) {
|
|
1230
|
+
this.editorService.setDefaultParagraphSeparator(this.config.defaultParagraphSeparator);
|
|
1231
|
+
}
|
|
1232
|
+
if (this.config.defaultFontName) {
|
|
1233
|
+
this.editorService.setFontName(this.config.defaultFontName);
|
|
1234
|
+
}
|
|
1235
|
+
if (this.config.defaultFontSize) {
|
|
1236
|
+
this.editorService.setFontSize(this.config.defaultFontSize);
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
getFonts() {
|
|
1240
|
+
const fonts = this.config.fonts ? this.config.fonts : angularEditorConfig.fonts;
|
|
1241
|
+
return fonts.map(x => {
|
|
1242
|
+
return { label: x.name, value: x.name };
|
|
1243
|
+
});
|
|
1244
|
+
}
|
|
1245
|
+
getCustomTags() {
|
|
1246
|
+
const tags = ['span'];
|
|
1247
|
+
this.config.customClasses.forEach(x => {
|
|
1248
|
+
if (x.tag !== undefined) {
|
|
1249
|
+
if (!tags.includes(x.tag)) {
|
|
1250
|
+
tags.push(x.tag);
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
});
|
|
1254
|
+
return tags.join(',');
|
|
1255
|
+
}
|
|
1256
|
+
ngOnDestroy() {
|
|
1257
|
+
if (this.blurInstance) {
|
|
1258
|
+
this.blurInstance();
|
|
1259
|
+
}
|
|
1260
|
+
if (this.focusInstance) {
|
|
1261
|
+
this.focusInstance();
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
filterStyles(html) {
|
|
1265
|
+
html = html.replace('position: fixed;', '');
|
|
1266
|
+
return html;
|
|
1267
|
+
}
|
|
1268
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.13", ngImport: i0, type: AngularEditorComponent, deps: [{ token: i0.Renderer2 }, { token: AngularEditorService }, { token: DOCUMENT }, { token: i2.DomSanitizer }, { token: i0.ChangeDetectorRef }, { token: 'tabindex', attribute: true }, { token: 'autofocus', attribute: true }], target: i0.ɵɵFactoryTarget.Component });
|
|
1269
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.13", type: AngularEditorComponent, isStandalone: false, selector: "angular-editor", inputs: { id: "id", config: "config", placeholder: "placeholder", tabIndex: "tabIndex" }, outputs: { html: "html", viewMode: "viewMode", blurEvent: "blur", focusEvent: "focus" }, host: { listeners: { "focus": "onFocus()" }, properties: { "attr.tabindex": "this.tabindex" } }, providers: [
|
|
1270
|
+
{
|
|
1271
|
+
provide: NG_VALUE_ACCESSOR,
|
|
1272
|
+
useExisting: forwardRef(() => AngularEditorComponent),
|
|
1273
|
+
multi: true
|
|
1274
|
+
},
|
|
1275
|
+
AngularEditorService
|
|
1276
|
+
], queries: [{ propertyName: "customButtonsTemplateRef", first: true, predicate: ["customButtons"], descendants: true }], viewQueries: [{ propertyName: "textArea", first: true, predicate: ["editor"], descendants: true, static: true }, { propertyName: "editorWrapper", first: true, predicate: ["editorWrapper"], descendants: true, static: true }, { propertyName: "editorToolbar", first: true, predicate: ["editorToolbar"], descendants: true }], ngImport: i0, template: "<div\n class=\"angular-editor\"\n #angularEditor\n [style.width]=\"config.width\"\n [style.minWidth]=\"config.minWidth\"\n [ngClass]=\"{\n 'bottom': config.toolbarPosition === 'bottom'\n }\"\n>\n <angular-editor-toolbar\n #editorToolbar\n [id]=\"id\"\n [uploadUrl]=\"config.uploadUrl\"\n [upload]=\"config.upload\"\n [showToolbar]=\"config.showToolbar !== undefined ? config.showToolbar : true\"\n [fonts]=\"getFonts()\"\n [customClasses]=\"config.customClasses\"\n [defaultFontName]=\"config.defaultFontName\"\n [defaultFontSize]=\"config.defaultFontSize\"\n [hiddenButtons]=\"config.toolbarHiddenButtons\"\n (execute)=\"executeCommand($event)\"\n >\n <ng-container\n [ngTemplateOutlet]=\"customButtonsTemplateRef\"\n [ngTemplateOutletContext]=\"{ executeCommandFn: this.executeCommandFn}\"\n >\n </ng-container>\n </angular-editor-toolbar>\n\n <div\n class=\"angular-editor-wrapper\"\n #editorWrapper\n >\n <div\n #editor\n class=\"angular-editor-textarea\"\n [attr.contenteditable]=\"config.editable\"\n [attr.tabindex]=\"disabled ? -1 : tabIndex\"\n [attr.translate]=\"config.translate\"\n [attr.spellcheck]=\"config.spellcheck\"\n [style.height]=\"config.height\"\n [style.minHeight]=\"config.minHeight\"\n [style.maxHeight]=\"config.maxHeight\"\n [style.outline]=\"config.outline === false ? 'none': undefined\"\n (input)=\"onContentChange($any($event.target))\"\n (focus)=\"onTextAreaFocus($event)\"\n (blur)=\"onTextAreaBlur($event)\"\n (click)=\"exec()\"\n (keyup)=\"exec()\"\n (mouseout)=\"onTextAreaMouseOut($event)\"\n (paste)=\"onPaste($event)\"\n >\n </div>\n <span class=\"angular-editor-placeholder\">{{ placeholder || config['placeholder'] }}</span>\n </div>\n</div>\n", styles: ["a{cursor:pointer}.angular-editor{display:flex;flex-direction:column;gap:var(--ae-gap, 5px)}.angular-editor.bottom{flex-direction:column-reverse}.angular-editor ::ng-deep [contenteditable=true]:empty:before{content:attr(placeholder);color:#868e96;opacity:1}.angular-editor .angular-editor-wrapper{position:relative}.angular-editor .angular-editor-wrapper .angular-editor-textarea{min-height:150px;overflow:auto;resize:vertical}.angular-editor .angular-editor-wrapper .angular-editor-textarea:after{content:\"\";position:absolute;bottom:0;right:0;display:block;width:8px;height:8px;cursor:nwse-resize;background-color:#ffffff80}.angular-editor .angular-editor-wrapper .angular-editor-textarea{min-height:5rem;padding:.5rem .8rem 1rem;border-radius:var(--ae-text-area-border-radius, .3rem);border:var(--ae-text-area-border, 1px solid #ddd);background-color:transparent;overflow-x:hidden;overflow-y:auto;position:relative}.angular-editor .angular-editor-wrapper .angular-editor-textarea:focus,.angular-editor .angular-editor-wrapper .angular-editor-textarea.focus{outline:var(--ae-focus-outline-color, -webkit-focus-ring-color auto 1px)}.angular-editor .angular-editor-wrapper .angular-editor-textarea ::ng-deep blockquote{margin-left:1rem;border-left:.2em solid #dfe2e5;padding-left:.5rem}.angular-editor .angular-editor-wrapper ::ng-deep p{margin-bottom:0}.angular-editor .angular-editor-wrapper .angular-editor-placeholder{display:none;position:absolute;top:0;padding:.6rem .8rem 1rem .9rem;color:#6c757d;opacity:.75}.angular-editor .angular-editor-wrapper.show-placeholder .angular-editor-placeholder{display:block}.angular-editor .angular-editor-wrapper.disabled{cursor:not-allowed;opacity:.5;pointer-events:none}\n"], dependencies: [{ kind: "directive", type: i1$1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1$1.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "component", type: AeToolbarComponent, selector: "angular-editor-toolbar, ae-toolbar, div[aeToolbar]", inputs: ["id", "uploadUrl", "upload", "showToolbar", "fonts", "customClasses", "defaultFontName", "defaultFontSize", "hiddenButtons"], outputs: ["execute"] }], encapsulation: i0.ViewEncapsulation.None });
|
|
1277
|
+
}
|
|
1278
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.13", ngImport: i0, type: AngularEditorComponent, decorators: [{
|
|
1279
|
+
type: Component,
|
|
1280
|
+
args: [{ selector: 'angular-editor', encapsulation: ViewEncapsulation.None, providers: [
|
|
1281
|
+
{
|
|
1282
|
+
provide: NG_VALUE_ACCESSOR,
|
|
1283
|
+
useExisting: forwardRef(() => AngularEditorComponent),
|
|
1284
|
+
multi: true
|
|
1285
|
+
},
|
|
1286
|
+
AngularEditorService
|
|
1287
|
+
], standalone: false, template: "<div\n class=\"angular-editor\"\n #angularEditor\n [style.width]=\"config.width\"\n [style.minWidth]=\"config.minWidth\"\n [ngClass]=\"{\n 'bottom': config.toolbarPosition === 'bottom'\n }\"\n>\n <angular-editor-toolbar\n #editorToolbar\n [id]=\"id\"\n [uploadUrl]=\"config.uploadUrl\"\n [upload]=\"config.upload\"\n [showToolbar]=\"config.showToolbar !== undefined ? config.showToolbar : true\"\n [fonts]=\"getFonts()\"\n [customClasses]=\"config.customClasses\"\n [defaultFontName]=\"config.defaultFontName\"\n [defaultFontSize]=\"config.defaultFontSize\"\n [hiddenButtons]=\"config.toolbarHiddenButtons\"\n (execute)=\"executeCommand($event)\"\n >\n <ng-container\n [ngTemplateOutlet]=\"customButtonsTemplateRef\"\n [ngTemplateOutletContext]=\"{ executeCommandFn: this.executeCommandFn}\"\n >\n </ng-container>\n </angular-editor-toolbar>\n\n <div\n class=\"angular-editor-wrapper\"\n #editorWrapper\n >\n <div\n #editor\n class=\"angular-editor-textarea\"\n [attr.contenteditable]=\"config.editable\"\n [attr.tabindex]=\"disabled ? -1 : tabIndex\"\n [attr.translate]=\"config.translate\"\n [attr.spellcheck]=\"config.spellcheck\"\n [style.height]=\"config.height\"\n [style.minHeight]=\"config.minHeight\"\n [style.maxHeight]=\"config.maxHeight\"\n [style.outline]=\"config.outline === false ? 'none': undefined\"\n (input)=\"onContentChange($any($event.target))\"\n (focus)=\"onTextAreaFocus($event)\"\n (blur)=\"onTextAreaBlur($event)\"\n (click)=\"exec()\"\n (keyup)=\"exec()\"\n (mouseout)=\"onTextAreaMouseOut($event)\"\n (paste)=\"onPaste($event)\"\n >\n </div>\n <span class=\"angular-editor-placeholder\">{{ placeholder || config['placeholder'] }}</span>\n </div>\n</div>\n", styles: ["a{cursor:pointer}.angular-editor{display:flex;flex-direction:column;gap:var(--ae-gap, 5px)}.angular-editor.bottom{flex-direction:column-reverse}.angular-editor ::ng-deep [contenteditable=true]:empty:before{content:attr(placeholder);color:#868e96;opacity:1}.angular-editor .angular-editor-wrapper{position:relative}.angular-editor .angular-editor-wrapper .angular-editor-textarea{min-height:150px;overflow:auto;resize:vertical}.angular-editor .angular-editor-wrapper .angular-editor-textarea:after{content:\"\";position:absolute;bottom:0;right:0;display:block;width:8px;height:8px;cursor:nwse-resize;background-color:#ffffff80}.angular-editor .angular-editor-wrapper .angular-editor-textarea{min-height:5rem;padding:.5rem .8rem 1rem;border-radius:var(--ae-text-area-border-radius, .3rem);border:var(--ae-text-area-border, 1px solid #ddd);background-color:transparent;overflow-x:hidden;overflow-y:auto;position:relative}.angular-editor .angular-editor-wrapper .angular-editor-textarea:focus,.angular-editor .angular-editor-wrapper .angular-editor-textarea.focus{outline:var(--ae-focus-outline-color, -webkit-focus-ring-color auto 1px)}.angular-editor .angular-editor-wrapper .angular-editor-textarea ::ng-deep blockquote{margin-left:1rem;border-left:.2em solid #dfe2e5;padding-left:.5rem}.angular-editor .angular-editor-wrapper ::ng-deep p{margin-bottom:0}.angular-editor .angular-editor-wrapper .angular-editor-placeholder{display:none;position:absolute;top:0;padding:.6rem .8rem 1rem .9rem;color:#6c757d;opacity:.75}.angular-editor .angular-editor-wrapper.show-placeholder .angular-editor-placeholder{display:block}.angular-editor .angular-editor-wrapper.disabled{cursor:not-allowed;opacity:.5;pointer-events:none}\n"] }]
|
|
1288
|
+
}], ctorParameters: () => [{ type: i0.Renderer2 }, { type: AngularEditorService }, { type: undefined, decorators: [{
|
|
1289
|
+
type: Inject,
|
|
1290
|
+
args: [DOCUMENT]
|
|
1291
|
+
}] }, { type: i2.DomSanitizer }, { type: i0.ChangeDetectorRef }, { type: undefined, decorators: [{
|
|
1292
|
+
type: Attribute,
|
|
1293
|
+
args: ['tabindex']
|
|
1294
|
+
}] }, { type: undefined, decorators: [{
|
|
1295
|
+
type: Attribute,
|
|
1296
|
+
args: ['autofocus']
|
|
1297
|
+
}] }], propDecorators: { id: [{
|
|
1298
|
+
type: Input
|
|
1299
|
+
}], config: [{
|
|
1300
|
+
type: Input
|
|
1301
|
+
}], placeholder: [{
|
|
1302
|
+
type: Input
|
|
1303
|
+
}], tabIndex: [{
|
|
1304
|
+
type: Input
|
|
1305
|
+
}], html: [{
|
|
1306
|
+
type: Output
|
|
1307
|
+
}], textArea: [{
|
|
1308
|
+
type: ViewChild,
|
|
1309
|
+
args: ['editor', { static: true }]
|
|
1310
|
+
}], editorWrapper: [{
|
|
1311
|
+
type: ViewChild,
|
|
1312
|
+
args: ['editorWrapper', { static: true }]
|
|
1313
|
+
}], editorToolbar: [{
|
|
1314
|
+
type: ViewChild,
|
|
1315
|
+
args: ['editorToolbar']
|
|
1316
|
+
}], customButtonsTemplateRef: [{
|
|
1317
|
+
type: ContentChild,
|
|
1318
|
+
args: ["customButtons"]
|
|
1319
|
+
}], viewMode: [{
|
|
1320
|
+
type: Output
|
|
1321
|
+
}], blurEvent: [{
|
|
1322
|
+
type: Output,
|
|
1323
|
+
args: ['blur']
|
|
1324
|
+
}], focusEvent: [{
|
|
1325
|
+
type: Output,
|
|
1326
|
+
args: ['focus']
|
|
1327
|
+
}], tabindex: [{
|
|
1328
|
+
type: HostBinding,
|
|
1329
|
+
args: ['attr.tabindex']
|
|
1330
|
+
}], onFocus: [{
|
|
1331
|
+
type: HostListener,
|
|
1332
|
+
args: ['focus']
|
|
1333
|
+
}] } });
|
|
1334
|
+
|
|
1335
|
+
class AngularEditorModule {
|
|
1336
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.13", ngImport: i0, type: AngularEditorModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
1337
|
+
static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.13", ngImport: i0, type: AngularEditorModule, declarations: [AngularEditorComponent, AeToolbarComponent, AeSelectComponent, AeButtonComponent, AeToolbarSetComponent], imports: [CommonModule, FormsModule, ReactiveFormsModule], exports: [AngularEditorComponent, AeToolbarComponent, AeButtonComponent, AeToolbarSetComponent] });
|
|
1338
|
+
static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.13", ngImport: i0, type: AngularEditorModule, imports: [CommonModule, FormsModule, ReactiveFormsModule] });
|
|
1339
|
+
}
|
|
1340
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.13", ngImport: i0, type: AngularEditorModule, decorators: [{
|
|
1341
|
+
type: NgModule,
|
|
1342
|
+
args: [{
|
|
1343
|
+
imports: [
|
|
1344
|
+
CommonModule, FormsModule, ReactiveFormsModule
|
|
1345
|
+
],
|
|
1346
|
+
declarations: [AngularEditorComponent, AeToolbarComponent, AeSelectComponent, AeButtonComponent, AeToolbarSetComponent],
|
|
1347
|
+
exports: [AngularEditorComponent, AeToolbarComponent, AeButtonComponent, AeToolbarSetComponent]
|
|
1348
|
+
}]
|
|
1349
|
+
}] });
|
|
1350
|
+
|
|
1351
|
+
/*
|
|
1352
|
+
* Public API Surface of angular-editor
|
|
1353
|
+
*/
|
|
1354
|
+
|
|
1355
|
+
/**
|
|
1356
|
+
* Generated bundle index. Do not edit.
|
|
1357
|
+
*/
|
|
1358
|
+
|
|
1359
|
+
export { AeButtonComponent, AeSelectComponent, AeToolbarComponent, AeToolbarSetComponent, AngularEditorComponent, AngularEditorModule, AngularEditorService };
|
|
1360
|
+
//# sourceMappingURL=kolkov-angular-editor.mjs.map
|