import { Component, Input, Output, EventEmitter, ViewChild } from "@angular/core"; import * as i0 from "@angular/core"; import * as i1 from "./email-composer/email-html-generator.service"; import * as i2 from "./email-composer/email-element.service"; import * as i3 from "@angular/common"; import * as i4 from "./email-plain-text/plain-text/plain-text.component"; import * as i5 from "./email-composer/email-composer-container/email-composer-container.component"; import * as i6 from "./email-composer/email-preview/email-preview.component"; import * as i7 from "./email-html-editor/email-html-editor/email-html-editor.component"; export class EmailEditorComponent { constructor(eh, elementsService) { Object.defineProperty(this, "eh", { enumerable: true, configurable: true, writable: true, value: eh }); Object.defineProperty(this, "elementsService", { enumerable: true, configurable: true, writable: true, value: elementsService }); Object.defineProperty(this, "emailComposer", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "type", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "template", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "isMobileView", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "isOffCanvasTrigger", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "emailContentChanged", { enumerable: true, configurable: true, writable: true, value: new EventEmitter() }); Object.defineProperty(this, "imageUploadTriggered", { enumerable: true, configurable: true, writable: true, value: new EventEmitter() }); Object.defineProperty(this, "imageSelectionTriggered", { enumerable: true, configurable: true, writable: true, value: new EventEmitter() }); Object.defineProperty(this, "closeSlideabr", { enumerable: true, configurable: true, writable: true, value: new EventEmitter() }); Object.defineProperty(this, "content", { enumerable: true, configurable: true, writable: true, value: '' }); Object.defineProperty(this, "previewType", { enumerable: true, configurable: true, writable: true, value: 'desktop' }); Object.defineProperty(this, "previewContent", { enumerable: true, configurable: true, writable: true, value: '' }); Object.defineProperty(this, "showPreviewPanel", { enumerable: true, configurable: true, writable: true, value: false }); } exportHtml() { let content = this.content.content; if (this.type === 'plain_text') { content = this.eh.getPainTextHTML(this.content.content); } else if (this.type === 'ses_designer') { content = this.eh.getEmailHtml(this.content.content); } content = this.addTargetBlankToLinks(content); return (content || '').trim(); } exportJSON() { return this.content; } onEmailContentChange(content) { this.content = content; this.emailContentChanged.emit(content); } showPreview() { this.previewType = 'desktop'; this.previewContent = this.exportHtml(); this.showPreviewPanel = true; } hidePreview() { this.showPreviewPanel = false; } showHtmlPreview() { this.previewType = 'html'; this.previewContent = this.exportHtml(); this.showPreviewPanel = true; } onImageSelectionTrigger(data) { this.imageSelectionTriggered.emit(data); } onImageUploadTrigger(data) { this.imageUploadTriggered.emit(data); } imageSelected(image, inputData) { if (inputData.source === 'footer') { inputData.src = image.src; this.elementsService.updateOrAddBrandList(null, inputData); } else { if (inputData.logo) { image.sizeType = 'original'; this.elementsService.updateLogoContent(image); this.elementsService.logoSelected$.next(true); } else { this.elementsService.updateImageVideoBlockContent(inputData.s, inputData.c, inputData.b, image); } } } openOffcanvas(slidebarStatus) { this.emailComposer.openOffcanvas(slidebarStatus); } closeSidebar(event) { this.closeSlideabr.emit(event); } addTargetBlankToLinks(htmlContent) { try { // Parse the input HTML string into a DOM Document const parser = new DOMParser(); const doc = parser.parseFromString(htmlContent, 'text/html'); // Select all anchor tags const anchorTags = doc.querySelectorAll('a'); // Check if every anchor tag has the target attribute set const allHaveTarget = Array.from(anchorTags).every((anchor) => { return anchor.hasAttribute('target') && anchor.getAttribute('target') !== '_self'; }); if (allHaveTarget) { return htmlContent; } else { //Iterate through each anchor tag anchorTags.forEach((anchor) => { // Check if 'target' is missing or explicitly set to '_self' if (!anchor.hasAttribute('target') || anchor.getAttribute('target') === '_self') { anchor.setAttribute('target', '_blank'); } }); // Serialize the modified document including the declaration const unformattedHTML = `\n${doc.documentElement.outerHTML}`; const formattedHTML = this.formatHTML(unformattedHTML); return formattedHTML; } } catch (error) { console.error('Error parsing HTML content:', error); return htmlContent; // Fallback to original content } } formatHTML(htmlString) { const indentSize = 2; let formattedHTML = ''; let indentLevel = 0; // Split the HTML string into tokens const tokens = htmlString .replace(/>\s+<') // Remove extra whitespace between tags .split(/(<[^>]+>)/g) // Split at HTML tags .filter((token) => token.trim()); // Remove empty tokens // Helper function to create indentation const createIndent = (level) => ' '.repeat(level * indentSize); for (let token of tokens) { if (token.startsWith('