diff --git a/src/pages/setting/Setting.tsx b/src/pages/setting/Setting.tsx index 2ad3e7d..a308b3c 100644 --- a/src/pages/setting/Setting.tsx +++ b/src/pages/setting/Setting.tsx @@ -106,7 +106,9 @@ const Setting: FC = () => { setIsSaveProcessing(true) try { + console.log('🔥 [Setting] Data before export:', JSON.stringify(data, null, 2)); const html = await exportPersonalityToHTML(data) + console.log('🔥 [Setting] HTML exported successfully, length:', html.length); setIsCapturingScreenshot(true) const screenshotFile = await capturePersonalityScreenshot(templateName) diff --git a/src/pages/setting/personality/utils/ExportHTML.ts b/src/pages/setting/personality/utils/ExportHTML.ts index 59cc226..cb7ebf6 100644 --- a/src/pages/setting/personality/utils/ExportHTML.ts +++ b/src/pages/setting/personality/utils/ExportHTML.ts @@ -23,6 +23,10 @@ import { export const exportPersonalityToHTML = async ( data: PersonalityDataType ): Promise => { + console.log( + "🔥 [ExportHTML] Starting export with data:", + JSON.stringify(data, null, 2) + ); // Helper functions const getHorizontalAlign = (alignment?: HorizontalAlignment) => { switch (alignment) { @@ -50,7 +54,11 @@ export const exportPersonalityToHTML = async ( // Render TextRenderer equivalent const renderTexts = (texts: TextType[]) => { - if (!texts || texts.length === 0) return ""; + console.log("🔥 [ExportHTML] renderTexts called with:", texts); + if (!texts || texts.length === 0) { + console.log("🔥 [ExportHTML] No texts to render"); + return ""; + } return texts .map( @@ -76,7 +84,11 @@ export const exportPersonalityToHTML = async ( // Render ButtonRenderer equivalent const renderButtons = (buttons: ButtonType[]) => { - if (!buttons || buttons.length === 0) return ""; + console.log("🔥 [ExportHTML] renderButtons called with:", buttons); + if (!buttons || buttons.length === 0) { + console.log("🔥 [ExportHTML] No buttons to render"); + return ""; + } return ` @@ -143,7 +155,11 @@ export const exportPersonalityToHTML = async ( // Render ImageRenderer equivalent const renderImages = (images: ImageType[]) => { - if (!images || images.length === 0) return ""; + console.log("🔥 [ExportHTML] renderImages called with:", images); + if (!images || images.length === 0) { + console.log("🔥 [ExportHTML] No images to render"); + return ""; + } const shouldUseBackgroundImage = (imageSize: ImageSize) => { return ( @@ -245,7 +261,11 @@ export const exportPersonalityToHTML = async ( // Render SocialRenderer equivalent const renderSocials = (socials: SocialType[]) => { - if (!socials || socials.length === 0) return ""; + console.log("🔥 [ExportHTML] renderSocials called with:", socials); + if (!socials || socials.length === 0) { + console.log("🔥 [ExportHTML] No socials to render"); + return ""; + } const getIconSize = (size: SocialIconSize) => { switch (size) { @@ -352,9 +372,15 @@ export const exportPersonalityToHTML = async ( const renderSection = ( section: SectionType, sectionHeight: string, - paddingTop = "", - isContentSection = false + paddingTop = "" ) => { + console.log(`🔥 [ExportHTML] Rendering section:`, { + columnsCount: section.columnsCount, + itemsLength: section.items?.length || 0, + sectionHeight, + items: section.items, + }); + if (section.columnsCount > 0) { return ` ${paddingTop ? ``; @@ -438,8 +481,11 @@ export const exportPersonalityToHTML = async ( ${renderImages(item?.images || [])} ${renderSocials(item?.socials || [])} ${ - isContentSection - ? '
{{content}}
' + sectionHeight === "246px" && + !hasTexts && + !hasImages && + !hasSocials + ? '
{{content}}
' : "" } @@ -458,6 +504,18 @@ export const exportPersonalityToHTML = async ( `; } } + } else { + // اگر هیچ محتوایی نداریم و content section است + console.log( + "🔥 [ExportHTML] Empty content section detected, adding {{content}} placeholder" + ); + if (sectionHeight === "246px") { + result += ` + + `; + } } result += ` @@ -516,12 +574,13 @@ export const exportPersonalityToHTML = async (
` : ""} @@ -378,6 +404,18 @@ export const exportPersonalityToHTML = async ( const hasSocials = item?.socials && item.socials.length > 0; + console.log( + `🔥 [ExportHTML] Item ${index} content check:`, + { + hasButtons, + hasTexts, + hasImages, + hasSocials, + sectionHeight, + item: item, + } + ); + let result = ` ${renderImages(item?.images || [])} ${renderSocials(item?.socials || [])} + ${ + sectionHeight === "246px" + ? '
{{content}}
' + : "" + } ${renderButtons(item.buttons)}
+
{{content}}
+
${renderSection(data.header, "123px")} - ${renderSection(data.content, "246px", "", true)} + ${renderSection(data.content, "246px", "")} ${renderSection(data.footer, "123px", "")}
`; + console.log("🔥 [ExportHTML] Final HTML generated:", html); return html; }; diff --git a/src/pages/setting/personality/utils/screenshotHelper.ts b/src/pages/setting/personality/utils/screenshotHelper.ts index 6929c9d..1f8ed26 100644 --- a/src/pages/setting/personality/utils/screenshotHelper.ts +++ b/src/pages/setting/personality/utils/screenshotHelper.ts @@ -20,7 +20,7 @@ const convertImagesToDataUrl = async (element: HTMLElement): Promise => { const tempImg = new Image(); tempImg.crossOrigin = "anonymous"; - await new Promise((resolve, reject) => { + await new Promise((resolve) => { tempImg.onload = () => { canvas.width = tempImg.width; canvas.height = tempImg.height;