import * as i1 from '@angular/common'; import { isPlatformServer, CommonModule } from '@angular/common'; import * as i0 from '@angular/core'; import { forwardRef, EventEmitter, afterNextRender, PLATFORM_ID, Component, ChangeDetectionStrategy, ViewEncapsulation, Inject, Input, Output, ContentChildren, ContentChild, NgModule } from '@angular/core'; import { NG_VALUE_ACCESSOR } from '@angular/forms'; import { Header, PrimeTemplate, SharedModule } from 'primeng/api'; import { DomHandler } from 'primeng/dom'; const EDITOR_VALUE_ACCESSOR = { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => Editor), multi: true }; /** * Editor groups a collection of contents in tabs. * @group Components */ class Editor { el; platformId; /** * Inline style of the container. * @group Props */ style; /** * Style class of the container. * @group Props */ styleClass; /** * Placeholder text to show when editor is empty. * @group Props */ placeholder; /** * Whitelist of formats to display, see here for available options. * @group Props */ formats; /** * Modules configuration of Editor, see here for available options. * @group Props */ modules; /** * DOM Element or a CSS selector for a DOM Element, within which the editor’s p elements (i.e. tooltips, etc.) should be confined. Currently, it only considers left and right boundaries. * @group Props */ bounds; /** * DOM Element or a CSS selector for a DOM Element, specifying which container has the scrollbars (i.e. overflow-y: auto), if is has been changed from the default ql-editor with custom CSS. Necessary to fix scroll jumping bugs when Quill is set to auto grow its height, and another ancestor container is responsible from the scrolling.. * @group Props */ scrollingContainer; /** * Shortcut for debug. Note debug is a static method and will affect other instances of Quill editors on the page. Only warning and error messages are enabled by default. * @group Props */ debug; /** * Whether to instantiate the editor to read-only mode. * @group Props */ get readonly() { return this._readonly; } set readonly(val) { this._readonly = val; if (this.quill) { if (this._readonly) this.quill.disable(); else this.quill.enable(); } } /** * Callback to invoke when the quill modules are loaded. * @param {EditorInitEvent} event - custom event. * @group Emits */ onInit = new EventEmitter(); /** * Callback to invoke when text of editor changes. * @param {EditorTextChangeEvent} event - custom event. * @group Emits */ onTextChange = new EventEmitter(); /** * Callback to invoke when selection of the text changes. * @param {EditorSelectionChangeEvent} event - custom event. * @group Emits */ onSelectionChange = new EventEmitter(); templates; toolbar; value; delayedCommand = null; _readonly = false; onModelChange = () => { }; onModelTouched = () => { }; quill; dynamicQuill; headerTemplate; get isAttachedQuillEditorToDOM() { return this.quillElements?.editorElement?.isConnected; } quillElements; constructor(el, platformId) { this.el = el; this.platformId = platformId; /** * Read or write the DOM once, when initializing non-Angular (Quill) library. */ afterNextRender(() => { this.initQuillElements(); this.initQuillEditor(); }); } ngAfterContentInit() { this.templates.forEach((item) => { switch (item.getType()) { case 'header': this.headerTemplate = item.template; break; } }); } writeValue(value) { this.value = value; if (this.quill) { if (value) { const command = () => { this.quill.setContents(this.quill.clipboard.convert(this.value)); }; if (this.isAttachedQuillEditorToDOM) { command(); } else { this.delayedCommand = command; } } else { const command = () => { this.quill.setText(''); }; if (this.isAttachedQuillEditorToDOM) { command(); } else { this.delayedCommand = command; } } } } registerOnChange(fn) { this.onModelChange = fn; } registerOnTouched(fn) { this.onModelTouched = fn; } getQuill() { return this.quill; } initQuillEditor() { if (isPlatformServer(this.platformId)) { return; } /** * Importing Quill at top level, throws `document is undefined` error during when * building for SSR, so this dynamically loads quill when it's in browser module. */ if (!this.dynamicQuill) { import('quill') .then((quillModule) => { this.dynamicQuill = quillModule.default; this.createQuillEditor(); }) .catch((e) => console.error(e.message)); } else { this.createQuillEditor(); } } createQuillEditor() { this.initQuillElements(); const { toolbarElement, editorElement } = this.quillElements; let defaultModule = { toolbar: toolbarElement }; let modules = this.modules ? { ...defaultModule, ...this.modules } : defaultModule; this.quill = new this.dynamicQuill(editorElement, { modules: modules, placeholder: this.placeholder, readOnly: this.readonly, theme: 'snow', formats: this.formats, bounds: this.bounds, debug: this.debug, scrollingContainer: this.scrollingContainer }); if (this.value) { this.quill.setContents(this.quill.clipboard.convert(this.value)); } this.quill.on('text-change', (delta, oldContents, source) => { if (source === 'user') { let html = DomHandler.findSingle(editorElement, '.ql-editor').innerHTML; let text = this.quill.getText().trim(); if (html === '