From 2a039c7e706f37eda01a7906f2767b6255b556d4 Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Thu, 7 Aug 2025 09:23:51 +0330 Subject: [PATCH] export html --- .../setting/personality/utils/ExportHTML.ts | 136 +++++++++++++++--- 1 file changed, 113 insertions(+), 23 deletions(-) diff --git a/src/pages/setting/personality/utils/ExportHTML.ts b/src/pages/setting/personality/utils/ExportHTML.ts index d4a8b73..7a72f8b 100644 --- a/src/pages/setting/personality/utils/ExportHTML.ts +++ b/src/pages/setting/personality/utils/ExportHTML.ts @@ -53,6 +53,19 @@ export const exportPersonalityToHTML = async ( } }; + // Helper function to get text alignment for email + const getTextAlignment = (alignment?: HorizontalAlignment) => { + switch (alignment) { + case HorizontalAlignment.LEFT: + return "left"; + case HorizontalAlignment.RIGHT: + return "right"; + case HorizontalAlignment.CENTER: + default: + return "center"; + } + }; + // Render TextRenderer equivalent const renderTexts = (texts: TextType[]) => { console.log("🔥 [ExportHTML] renderTexts called with:", texts); @@ -67,9 +80,13 @@ export const exportPersonalityToHTML = async ( ` - - ${paddingTop ? `
{ + if (!border || border.style === "none") { + return ""; + } + + const { + width = "0px", + color = "#E5E7EB", + style = "solid", + sides = [], + } = border; + + // اگر width صفر باشد یا تعریف نشده باشد، border نمایش نده + if (!width || width === "0px") { + return ""; + } + + if (sides.length === 0 || sides.length === 4) { + return `border: ${width} ${style} ${color};`; + } + + // Generate individual border sides + const borderStyles: string[] = []; + sides.forEach((side) => { + borderStyles.push(`border-${side}: ${width} ${style} ${color}`); + }); + + return borderStyles.join("; ") + ";"; + }; + // Render section equivalent (HeaderSection, ContentSection, FooterSection) const renderSection = ( section: SectionType & { name?: string; isContent?: boolean }, - sectionHeight: string, - paddingTop = "" + sectionHeight: string ) => { console.log(`🔥 [ExportHTML] Rendering section:`, { columnsCount: section.columnsCount, @@ -381,13 +433,21 @@ export const exportPersonalityToHTML = async ( }); if (section.columnsCount > 0) { - return `
` : ""} - + return ` +
+ -
- +
+ ${Array.from( @@ -432,7 +492,9 @@ export const exportPersonalityToHTML = async ( };` : "" } padding: 0; vertical-align: top; border-radius: 8px; position: relative;"> -
+
`; // اگر محتوایی وجود دارد (متن، دکمه، تصویر، یا شبکه اجتماعی) @@ -449,7 +511,11 @@ export const exportPersonalityToHTML = async ( item.buttons[0] )}" valign="${getButtonVerticalAlign( item.buttons[0] - )}" style="padding: 8px;"> + )}" style="padding: 8px; text-align: ${getButtonHorizontalAlign( + item.buttons[0] + )}; vertical-align: ${getButtonVerticalAlign( + item.buttons[0] + )}; ${generateBorderStyle(section.border)}"> ${renderImages(item?.images || [])} ${renderSocials(item?.socials || [])} ${ @@ -475,8 +541,22 @@ export const exportPersonalityToHTML = async ( 30 ).toString(); + const textAlignment = hasTexts + ? getTextAlignment(item.texts[0]?.alignment) + : "center"; + const textVerticalAlignment = + hasTexts && item.texts[0]?.verticalAlignment + ? item.texts[0].verticalAlignment === "top" + ? "top" + : item.texts[0].verticalAlignment === + "bottom" + ? "bottom" + : "middle" + : "middle"; result += ` - `; @@ -522,7 +606,9 @@ export const exportPersonalityToHTML = async ( 30 ); result += ` - `; @@ -570,13 +656,17 @@ export const exportPersonalityToHTML = async ( ? Math.max(sectionHeightNumber + 40, 286) : sectionHeight; - return ` - ${paddingTop ? `
+ ${renderTexts(item?.texts || [])} ${renderImages(item?.images || [])} ${renderSocials(item?.socials || [])} @@ -498,7 +578,11 @@ export const exportPersonalityToHTML = async ( item.buttons[0] )}" valign="${getButtonVerticalAlign( item.buttons[0] - )}" style="padding: 0 8px 8px 8px;"> + )}" style="padding: 0 8px 8px 8px; text-align: ${getButtonHorizontalAlign( + item.buttons[0] + )}; vertical-align: ${getButtonVerticalAlign( + item.buttons[0] + )}; ${generateBorderStyle(section.border)}"> ${renderButtons(item.buttons)}
+
{{content}}
` : ""} - + return ` +
+ - @@ -639,8 +729,8 @@ export const exportPersonalityToHTML = async ( isContent: sectionData.isContent, }); - // Pass the complete section data for rendering - const renderedSection = renderSection(sectionData, height, ""); + // Pass the complete section data for rendering with no spacing + const renderedSection = renderSection(sectionData, height); console.log( `🔥 [ExportHTML] Section ${sectionKey} rendered, HTML length:`, renderedSection.length @@ -660,7 +750,7 @@ export const exportPersonalityToHTML = async ( ); const html = `
-
-
+
+
${emptyMessage}
+
${sectionsHtml}