UNPKG

21.2 kBJavaScriptView Raw
1import { __decorate, __extends, __assign, __param } from 'tslib';
2import { EventEmitter, Output, InjectionToken, forwardRef, ElementRef, NgZone, Inject, PLATFORM_ID, Optional, Input, Component, NgModule } from '@angular/core';
3import { isPlatformBrowser, CommonModule } from '@angular/common';
4import { NG_VALUE_ACCESSOR, FormsModule } from '@angular/forms';
5
6/**
7 * Copyright (c) 2017-present, Ephox, Inc.
8 *
9 * This source code is licensed under the Apache 2 license found in the
10 * LICENSE file in the root directory of this source tree.
11 *
12 */
13var getTinymce = function () {
14 var w = typeof window !== 'undefined' ? window : undefined;
15 return w && w.tinymce ? w.tinymce : null;
16};
17var ɵ0 = getTinymce;
18
19var Events = /** @class */ (function () {
20 function Events() {
21 this.onBeforePaste = new EventEmitter();
22 this.onBlur = new EventEmitter();
23 this.onClick = new EventEmitter();
24 this.onContextMenu = new EventEmitter();
25 this.onCopy = new EventEmitter();
26 this.onCut = new EventEmitter();
27 this.onDblclick = new EventEmitter();
28 this.onDrag = new EventEmitter();
29 this.onDragDrop = new EventEmitter();
30 this.onDragEnd = new EventEmitter();
31 this.onDragGesture = new EventEmitter();
32 this.onDragOver = new EventEmitter();
33 this.onDrop = new EventEmitter();
34 this.onFocus = new EventEmitter();
35 this.onFocusIn = new EventEmitter();
36 this.onFocusOut = new EventEmitter();
37 this.onKeyDown = new EventEmitter();
38 this.onKeyPress = new EventEmitter();
39 this.onKeyUp = new EventEmitter();
40 this.onMouseDown = new EventEmitter();
41 this.onMouseEnter = new EventEmitter();
42 this.onMouseLeave = new EventEmitter();
43 this.onMouseMove = new EventEmitter();
44 this.onMouseOut = new EventEmitter();
45 this.onMouseOver = new EventEmitter();
46 this.onMouseUp = new EventEmitter();
47 this.onPaste = new EventEmitter();
48 this.onSelectionChange = new EventEmitter();
49 this.onActivate = new EventEmitter();
50 this.onAddUndo = new EventEmitter();
51 this.onBeforeAddUndo = new EventEmitter();
52 this.onBeforeExecCommand = new EventEmitter();
53 this.onBeforeGetContent = new EventEmitter();
54 this.onBeforeRenderUI = new EventEmitter();
55 this.onBeforeSetContent = new EventEmitter();
56 this.onChange = new EventEmitter();
57 this.onClearUndos = new EventEmitter();
58 this.onDeactivate = new EventEmitter();
59 this.onDirty = new EventEmitter();
60 this.onExecCommand = new EventEmitter();
61 this.onGetContent = new EventEmitter();
62 this.onHide = new EventEmitter();
63 this.onInit = new EventEmitter();
64 this.onLoadContent = new EventEmitter();
65 this.onNodeChange = new EventEmitter();
66 this.onPostProcess = new EventEmitter();
67 this.onPostRender = new EventEmitter();
68 this.onPreInit = new EventEmitter();
69 this.onPreProcess = new EventEmitter();
70 this.onProgressState = new EventEmitter();
71 this.onRedo = new EventEmitter();
72 this.onRemove = new EventEmitter();
73 this.onReset = new EventEmitter();
74 this.onSaveContent = new EventEmitter();
75 this.onSetAttrib = new EventEmitter();
76 this.onObjectResizeStart = new EventEmitter();
77 this.onObjectResized = new EventEmitter();
78 this.onObjectSelected = new EventEmitter();
79 this.onSetContent = new EventEmitter();
80 this.onShow = new EventEmitter();
81 this.onSubmit = new EventEmitter();
82 this.onUndo = new EventEmitter();
83 this.onVisualAid = new EventEmitter();
84 }
85 __decorate([
86 Output()
87 ], Events.prototype, "onBeforePaste", void 0);
88 __decorate([
89 Output()
90 ], Events.prototype, "onBlur", void 0);
91 __decorate([
92 Output()
93 ], Events.prototype, "onClick", void 0);
94 __decorate([
95 Output()
96 ], Events.prototype, "onContextMenu", void 0);
97 __decorate([
98 Output()
99 ], Events.prototype, "onCopy", void 0);
100 __decorate([
101 Output()
102 ], Events.prototype, "onCut", void 0);
103 __decorate([
104 Output()
105 ], Events.prototype, "onDblclick", void 0);
106 __decorate([
107 Output()
108 ], Events.prototype, "onDrag", void 0);
109 __decorate([
110 Output()
111 ], Events.prototype, "onDragDrop", void 0);
112 __decorate([
113 Output()
114 ], Events.prototype, "onDragEnd", void 0);
115 __decorate([
116 Output()
117 ], Events.prototype, "onDragGesture", void 0);
118 __decorate([
119 Output()
120 ], Events.prototype, "onDragOver", void 0);
121 __decorate([
122 Output()
123 ], Events.prototype, "onDrop", void 0);
124 __decorate([
125 Output()
126 ], Events.prototype, "onFocus", void 0);
127 __decorate([
128 Output()
129 ], Events.prototype, "onFocusIn", void 0);
130 __decorate([
131 Output()
132 ], Events.prototype, "onFocusOut", void 0);
133 __decorate([
134 Output()
135 ], Events.prototype, "onKeyDown", void 0);
136 __decorate([
137 Output()
138 ], Events.prototype, "onKeyPress", void 0);
139 __decorate([
140 Output()
141 ], Events.prototype, "onKeyUp", void 0);
142 __decorate([
143 Output()
144 ], Events.prototype, "onMouseDown", void 0);
145 __decorate([
146 Output()
147 ], Events.prototype, "onMouseEnter", void 0);
148 __decorate([
149 Output()
150 ], Events.prototype, "onMouseLeave", void 0);
151 __decorate([
152 Output()
153 ], Events.prototype, "onMouseMove", void 0);
154 __decorate([
155 Output()
156 ], Events.prototype, "onMouseOut", void 0);
157 __decorate([
158 Output()
159 ], Events.prototype, "onMouseOver", void 0);
160 __decorate([
161 Output()
162 ], Events.prototype, "onMouseUp", void 0);
163 __decorate([
164 Output()
165 ], Events.prototype, "onPaste", void 0);
166 __decorate([
167 Output()
168 ], Events.prototype, "onSelectionChange", void 0);
169 __decorate([
170 Output()
171 ], Events.prototype, "onActivate", void 0);
172 __decorate([
173 Output()
174 ], Events.prototype, "onAddUndo", void 0);
175 __decorate([
176 Output()
177 ], Events.prototype, "onBeforeAddUndo", void 0);
178 __decorate([
179 Output()
180 ], Events.prototype, "onBeforeExecCommand", void 0);
181 __decorate([
182 Output()
183 ], Events.prototype, "onBeforeGetContent", void 0);
184 __decorate([
185 Output()
186 ], Events.prototype, "onBeforeRenderUI", void 0);
187 __decorate([
188 Output()
189 ], Events.prototype, "onBeforeSetContent", void 0);
190 __decorate([
191 Output()
192 ], Events.prototype, "onChange", void 0);
193 __decorate([
194 Output()
195 ], Events.prototype, "onClearUndos", void 0);
196 __decorate([
197 Output()
198 ], Events.prototype, "onDeactivate", void 0);
199 __decorate([
200 Output()
201 ], Events.prototype, "onDirty", void 0);
202 __decorate([
203 Output()
204 ], Events.prototype, "onExecCommand", void 0);
205 __decorate([
206 Output()
207 ], Events.prototype, "onGetContent", void 0);
208 __decorate([
209 Output()
210 ], Events.prototype, "onHide", void 0);
211 __decorate([
212 Output()
213 ], Events.prototype, "onInit", void 0);
214 __decorate([
215 Output()
216 ], Events.prototype, "onLoadContent", void 0);
217 __decorate([
218 Output()
219 ], Events.prototype, "onNodeChange", void 0);
220 __decorate([
221 Output()
222 ], Events.prototype, "onPostProcess", void 0);
223 __decorate([
224 Output()
225 ], Events.prototype, "onPostRender", void 0);
226 __decorate([
227 Output()
228 ], Events.prototype, "onPreInit", void 0);
229 __decorate([
230 Output()
231 ], Events.prototype, "onPreProcess", void 0);
232 __decorate([
233 Output()
234 ], Events.prototype, "onProgressState", void 0);
235 __decorate([
236 Output()
237 ], Events.prototype, "onRedo", void 0);
238 __decorate([
239 Output()
240 ], Events.prototype, "onRemove", void 0);
241 __decorate([
242 Output()
243 ], Events.prototype, "onReset", void 0);
244 __decorate([
245 Output()
246 ], Events.prototype, "onSaveContent", void 0);
247 __decorate([
248 Output()
249 ], Events.prototype, "onSetAttrib", void 0);
250 __decorate([
251 Output()
252 ], Events.prototype, "onObjectResizeStart", void 0);
253 __decorate([
254 Output()
255 ], Events.prototype, "onObjectResized", void 0);
256 __decorate([
257 Output()
258 ], Events.prototype, "onObjectSelected", void 0);
259 __decorate([
260 Output()
261 ], Events.prototype, "onSetContent", void 0);
262 __decorate([
263 Output()
264 ], Events.prototype, "onShow", void 0);
265 __decorate([
266 Output()
267 ], Events.prototype, "onSubmit", void 0);
268 __decorate([
269 Output()
270 ], Events.prototype, "onUndo", void 0);
271 __decorate([
272 Output()
273 ], Events.prototype, "onVisualAid", void 0);
274 return Events;
275}());
276var validEvents = [
277 'onActivate',
278 'onAddUndo',
279 'onBeforeAddUndo',
280 'onBeforeExecCommand',
281 'onBeforeGetContent',
282 'onBeforeRenderUI',
283 'onBeforeSetContent',
284 'onBeforePaste',
285 'onBlur',
286 'onChange',
287 'onClearUndos',
288 'onClick',
289 'onContextMenu',
290 'onCopy',
291 'onCut',
292 'onDblclick',
293 'onDeactivate',
294 'onDirty',
295 'onDrag',
296 'onDragDrop',
297 'onDragEnd',
298 'onDragGesture',
299 'onDragOver',
300 'onDrop',
301 'onExecCommand',
302 'onFocus',
303 'onFocusIn',
304 'onFocusOut',
305 'onGetContent',
306 'onHide',
307 'onInit',
308 'onKeyDown',
309 'onKeyPress',
310 'onKeyUp',
311 'onLoadContent',
312 'onMouseDown',
313 'onMouseEnter',
314 'onMouseLeave',
315 'onMouseMove',
316 'onMouseOut',
317 'onMouseOver',
318 'onMouseUp',
319 'onNodeChange',
320 'onObjectResizeStart',
321 'onObjectResized',
322 'onObjectSelected',
323 'onPaste',
324 'onPostProcess',
325 'onPostRender',
326 'onPreProcess',
327 'onProgressState',
328 'onRedo',
329 'onRemove',
330 'onReset',
331 'onSaveContent',
332 'onSelectionChange',
333 'onSetAttrib',
334 'onSetContent',
335 'onShow',
336 'onSubmit',
337 'onUndo',
338 'onVisualAid'
339];
340
341/**
342 * Copyright (c) 2017-present, Ephox, Inc.
343 *
344 * This source code is licensed under the Apache 2 license found in the
345 * LICENSE file in the root directory of this source tree.
346 *
347 */
348var bindHandlers = function (ctx, editor, initEvent) {
349 validEvents.forEach(function (eventName) {
350 var eventEmitter = ctx[eventName];
351 if (eventName === 'onInit') {
352 ctx.ngZone.run(function () { return eventEmitter.emit({ event: initEvent, editor: editor }); });
353 }
354 else {
355 editor.on(eventName.substring(2), function (event) { return ctx.ngZone.run(function () { return eventEmitter.emit({ event: event, editor: editor }); }); });
356 }
357 });
358};
359var ɵ0$1 = bindHandlers;
360var unique = 0;
361var uuid = function (prefix) {
362 var date = new Date();
363 var time = date.getTime();
364 var random = Math.floor(Math.random() * 1000000000);
365 unique++;
366 return prefix + '_' + random + unique + String(time);
367};
368var ɵ1 = uuid;
369var isTextarea = function (element) {
370 return typeof element !== 'undefined' && element.tagName.toLowerCase() === 'textarea';
371};
372var ɵ2 = isTextarea;
373var normalizePluginArray = function (plugins) {
374 if (typeof plugins === 'undefined' || plugins === '') {
375 return [];
376 }
377 return Array.isArray(plugins) ? plugins : plugins.split(' ');
378};
379var ɵ3 = normalizePluginArray;
380var mergePlugins = function (initPlugins, inputPlugins) {
381 return normalizePluginArray(initPlugins).concat(normalizePluginArray(inputPlugins));
382};
383var ɵ4 = mergePlugins;
384// tslint:disable-next-line:no-empty
385var noop = function () { };
386var ɵ5 = noop;
387var isNullOrUndefined = function (value) { return value === null || value === undefined; };
388var ɵ6 = isNullOrUndefined;
389
390/**
391 * Copyright (c) 2017-present, Ephox, Inc.
392 *
393 * This source code is licensed under the Apache 2 license found in the
394 * LICENSE file in the root directory of this source tree.
395 *
396 */
397var createState = function () {
398 return {
399 listeners: [],
400 scriptId: uuid('tiny-script'),
401 scriptLoaded: false
402 };
403};
404var ɵ0$2 = createState;
405var CreateScriptLoader = function () {
406 var state = createState();
407 var injectScriptTag = function (scriptId, doc, url, callback) {
408 var scriptTag = doc.createElement('script');
409 scriptTag.referrerPolicy = 'origin';
410 scriptTag.type = 'application/javascript';
411 scriptTag.id = scriptId;
412 scriptTag.src = url;
413 var handler = function () {
414 scriptTag.removeEventListener('load', handler);
415 callback();
416 };
417 scriptTag.addEventListener('load', handler);
418 if (doc.head) {
419 doc.head.appendChild(scriptTag);
420 }
421 };
422 var load = function (doc, url, callback) {
423 if (state.scriptLoaded) {
424 callback();
425 }
426 else {
427 state.listeners.push(callback);
428 if (!doc.getElementById(state.scriptId)) {
429 injectScriptTag(state.scriptId, doc, url, function () {
430 state.listeners.forEach(function (fn) { return fn(); });
431 state.scriptLoaded = true;
432 });
433 }
434 }
435 };
436 // Only to be used by tests.
437 var reinitialize = function () {
438 state = createState();
439 };
440 return {
441 load: load,
442 reinitialize: reinitialize
443 };
444};
445var ɵ1$1 = CreateScriptLoader;
446var ScriptLoader = CreateScriptLoader();
447
448var TINYMCE_SCRIPT_SRC = new InjectionToken('TINYMCE_SCRIPT_SRC');
449var EDITOR_COMPONENT_VALUE_ACCESSOR = {
450 provide: NG_VALUE_ACCESSOR,
451 useExisting: forwardRef(function () { return EditorComponent; }),
452 multi: true
453};
454var EditorComponent = /** @class */ (function (_super) {
455 __extends(EditorComponent, _super);
456 function EditorComponent(elementRef, ngZone, platformId, tinymceScriptSrc) {
457 var _this = _super.call(this) || this;
458 _this.platformId = platformId;
459 _this.tinymceScriptSrc = tinymceScriptSrc;
460 _this.cloudChannel = '5';
461 _this.apiKey = 'no-api-key';
462 _this.id = '';
463 _this.onTouchedCallback = noop;
464 _this.onChangeCallback = noop;
465 _this._elementRef = elementRef;
466 _this.ngZone = ngZone;
467 _this.initialise = _this.initialise.bind(_this);
468 return _this;
469 }
470 Object.defineProperty(EditorComponent.prototype, "disabled", {
471 get: function () {
472 return this._disabled;
473 },
474 set: function (val) {
475 this._disabled = val;
476 if (this._editor && this._editor.initialized) {
477 this._editor.setMode(val ? 'readonly' : 'design');
478 }
479 },
480 enumerable: true,
481 configurable: true
482 });
483 Object.defineProperty(EditorComponent.prototype, "editor", {
484 get: function () {
485 return this._editor;
486 },
487 enumerable: true,
488 configurable: true
489 });
490 EditorComponent.prototype.writeValue = function (value) {
491 if (this._editor && this._editor.initialized) {
492 this._editor.setContent(isNullOrUndefined(value) ? '' : value);
493 }
494 else {
495 this.initialValue = value === null ? undefined : value;
496 }
497 };
498 EditorComponent.prototype.registerOnChange = function (fn) {
499 this.onChangeCallback = fn;
500 };
501 EditorComponent.prototype.registerOnTouched = function (fn) {
502 this.onTouchedCallback = fn;
503 };
504 EditorComponent.prototype.setDisabledState = function (isDisabled) {
505 if (this._editor) {
506 this._editor.setMode(isDisabled ? 'readonly' : 'design');
507 }
508 else if (isDisabled) {
509 this.init = __assign({}, this.init, { readonly: true });
510 }
511 };
512 EditorComponent.prototype.ngAfterViewInit = function () {
513 if (isPlatformBrowser(this.platformId)) {
514 this.id = this.id || uuid('tiny-angular');
515 this.inline =
516 typeof this.inline !== 'undefined' ? (typeof this.inline === 'boolean' ? this.inline : true) : this.init && this.init.inline;
517 this.createElement();
518 if (getTinymce() !== null) {
519 this.initialise();
520 }
521 else if (this._element && this._element.ownerDocument) {
522 ScriptLoader.load(this._element.ownerDocument, this.getScriptSrc(), this.initialise);
523 }
524 }
525 };
526 EditorComponent.prototype.ngOnDestroy = function () {
527 if (getTinymce() !== null) {
528 getTinymce().remove(this._editor);
529 }
530 };
531 EditorComponent.prototype.createElement = function () {
532 var tagName = typeof this.tagName === 'string' ? this.tagName : 'div';
533 this._element = document.createElement(this.inline ? tagName : 'textarea');
534 if (this._element) {
535 this._element.id = this.id;
536 if (isTextarea(this._element)) {
537 this._element.style.visibility = 'hidden';
538 }
539 this._elementRef.nativeElement.appendChild(this._element);
540 }
541 };
542 EditorComponent.prototype.initialise = function () {
543 var _this = this;
544 var finalInit = __assign({}, this.init, { target: this._element, inline: this.inline, readonly: this.disabled, plugins: mergePlugins(this.init && this.init.plugins, this.plugins), toolbar: this.toolbar || (this.init && this.init.toolbar), setup: function (editor) {
545 _this._editor = editor;
546 editor.on('init', function (e) {
547 _this.initEditor(e, editor);
548 });
549 if (_this.init && typeof _this.init.setup === 'function') {
550 _this.init.setup(editor);
551 }
552 } });
553 if (isTextarea(this._element)) {
554 this._element.style.visibility = '';
555 }
556 this.ngZone.runOutsideAngular(function () {
557 getTinymce().init(finalInit);
558 });
559 };
560 EditorComponent.prototype.getScriptSrc = function () {
561 return isNullOrUndefined(this.tinymceScriptSrc) ?
562 "https://cdn.tiny.cloud/1/" + this.apiKey + "/tinymce/" + this.cloudChannel + "/tinymce.min.js" :
563 this.tinymceScriptSrc;
564 };
565 EditorComponent.prototype.initEditor = function (initEvent, editor) {
566 var _this = this;
567 if (typeof this.initialValue === 'string') {
568 this.ngZone.run(function () { return editor.setContent(_this.initialValue); });
569 }
570 editor.on('blur', function () { return _this.ngZone.run(function () { return _this.onTouchedCallback(); }); });
571 editor.on('change keyup undo redo', function () {
572 _this.ngZone.run(function () { return _this.onChangeCallback(editor.getContent({ format: _this.outputFormat })); });
573 });
574 bindHandlers(this, editor, initEvent);
575 };
576 EditorComponent.ctorParameters = function () { return [
577 { type: ElementRef },
578 { type: NgZone },
579 { type: Object, decorators: [{ type: Inject, args: [PLATFORM_ID,] }] },
580 { type: String, decorators: [{ type: Optional }, { type: Inject, args: [TINYMCE_SCRIPT_SRC,] }] }
581 ]; };
582 __decorate([
583 Input()
584 ], EditorComponent.prototype, "disabled", null);
585 __decorate([
586 Input()
587 ], EditorComponent.prototype, "cloudChannel", void 0);
588 __decorate([
589 Input()
590 ], EditorComponent.prototype, "apiKey", void 0);
591 __decorate([
592 Input()
593 ], EditorComponent.prototype, "init", void 0);
594 __decorate([
595 Input()
596 ], EditorComponent.prototype, "id", void 0);
597 __decorate([
598 Input()
599 ], EditorComponent.prototype, "initialValue", void 0);
600 __decorate([
601 Input()
602 ], EditorComponent.prototype, "outputFormat", void 0);
603 __decorate([
604 Input()
605 ], EditorComponent.prototype, "inline", void 0);
606 __decorate([
607 Input()
608 ], EditorComponent.prototype, "tagName", void 0);
609 __decorate([
610 Input()
611 ], EditorComponent.prototype, "plugins", void 0);
612 __decorate([
613 Input()
614 ], EditorComponent.prototype, "toolbar", void 0);
615 EditorComponent = __decorate([
616 Component({
617 selector: 'editor',
618 template: '<ng-template></ng-template>',
619 providers: [EDITOR_COMPONENT_VALUE_ACCESSOR],
620 styles: [':host { display: block; }']
621 }),
622 __param(2, Inject(PLATFORM_ID)),
623 __param(3, Optional()), __param(3, Inject(TINYMCE_SCRIPT_SRC))
624 ], EditorComponent);
625 return EditorComponent;
626}(Events));
627
628var EditorModule = /** @class */ (function () {
629 function EditorModule() {
630 }
631 EditorModule = __decorate([
632 NgModule({
633 imports: [CommonModule, FormsModule],
634 declarations: [EditorComponent],
635 exports: [EditorComponent]
636 })
637 ], EditorModule);
638 return EditorModule;
639}());
640
641/**
642 * Generated bundle index. Do not edit.
643 */
644
645export { EditorComponent, EditorModule, TINYMCE_SCRIPT_SRC, Events as ɵa };
646//# sourceMappingURL=tinymce-tinymce-angular.js.map