content text
This commit is contained in:
@@ -106,7 +106,9 @@ const Setting: FC = () => {
|
|||||||
setIsSaveProcessing(true)
|
setIsSaveProcessing(true)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
console.log('🔥 [Setting] Data before export:', JSON.stringify(data, null, 2));
|
||||||
const html = await exportPersonalityToHTML(data)
|
const html = await exportPersonalityToHTML(data)
|
||||||
|
console.log('🔥 [Setting] HTML exported successfully, length:', html.length);
|
||||||
|
|
||||||
setIsCapturingScreenshot(true)
|
setIsCapturingScreenshot(true)
|
||||||
const screenshotFile = await capturePersonalityScreenshot(templateName)
|
const screenshotFile = await capturePersonalityScreenshot(templateName)
|
||||||
|
|||||||
@@ -23,6 +23,10 @@ import {
|
|||||||
export const exportPersonalityToHTML = async (
|
export const exportPersonalityToHTML = async (
|
||||||
data: PersonalityDataType
|
data: PersonalityDataType
|
||||||
): Promise<string> => {
|
): Promise<string> => {
|
||||||
|
console.log(
|
||||||
|
"🔥 [ExportHTML] Starting export with data:",
|
||||||
|
JSON.stringify(data, null, 2)
|
||||||
|
);
|
||||||
// Helper functions
|
// Helper functions
|
||||||
const getHorizontalAlign = (alignment?: HorizontalAlignment) => {
|
const getHorizontalAlign = (alignment?: HorizontalAlignment) => {
|
||||||
switch (alignment) {
|
switch (alignment) {
|
||||||
@@ -50,7 +54,11 @@ export const exportPersonalityToHTML = async (
|
|||||||
|
|
||||||
// Render TextRenderer equivalent
|
// Render TextRenderer equivalent
|
||||||
const renderTexts = (texts: TextType[]) => {
|
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
|
return texts
|
||||||
.map(
|
.map(
|
||||||
@@ -76,7 +84,11 @@ export const exportPersonalityToHTML = async (
|
|||||||
|
|
||||||
// Render ButtonRenderer equivalent
|
// Render ButtonRenderer equivalent
|
||||||
const renderButtons = (buttons: ButtonType[]) => {
|
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 `<table width="100%" cellpadding="0" cellspacing="0" border="0" style="border-collapse: collapse;">
|
return `<table width="100%" cellpadding="0" cellspacing="0" border="0" style="border-collapse: collapse;">
|
||||||
<tbody>
|
<tbody>
|
||||||
@@ -143,7 +155,11 @@ export const exportPersonalityToHTML = async (
|
|||||||
|
|
||||||
// Render ImageRenderer equivalent
|
// Render ImageRenderer equivalent
|
||||||
const renderImages = (images: ImageType[]) => {
|
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) => {
|
const shouldUseBackgroundImage = (imageSize: ImageSize) => {
|
||||||
return (
|
return (
|
||||||
@@ -245,7 +261,11 @@ export const exportPersonalityToHTML = async (
|
|||||||
|
|
||||||
// Render SocialRenderer equivalent
|
// Render SocialRenderer equivalent
|
||||||
const renderSocials = (socials: SocialType[]) => {
|
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) => {
|
const getIconSize = (size: SocialIconSize) => {
|
||||||
switch (size) {
|
switch (size) {
|
||||||
@@ -352,9 +372,15 @@ export const exportPersonalityToHTML = async (
|
|||||||
const renderSection = (
|
const renderSection = (
|
||||||
section: SectionType,
|
section: SectionType,
|
||||||
sectionHeight: string,
|
sectionHeight: string,
|
||||||
paddingTop = "",
|
paddingTop = ""
|
||||||
isContentSection = false
|
|
||||||
) => {
|
) => {
|
||||||
|
console.log(`🔥 [ExportHTML] Rendering section:`, {
|
||||||
|
columnsCount: section.columnsCount,
|
||||||
|
itemsLength: section.items?.length || 0,
|
||||||
|
sectionHeight,
|
||||||
|
items: section.items,
|
||||||
|
});
|
||||||
|
|
||||||
if (section.columnsCount > 0) {
|
if (section.columnsCount > 0) {
|
||||||
return `<tr>
|
return `<tr>
|
||||||
${paddingTop ? `<td style="padding-top: ${paddingTop};">` : "<td>"}
|
${paddingTop ? `<td style="padding-top: ${paddingTop};">` : "<td>"}
|
||||||
@@ -378,6 +404,18 @@ export const exportPersonalityToHTML = async (
|
|||||||
const hasSocials =
|
const hasSocials =
|
||||||
item?.socials && item.socials.length > 0;
|
item?.socials && item.socials.length > 0;
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`🔥 [ExportHTML] Item ${index} content check:`,
|
||||||
|
{
|
||||||
|
hasButtons,
|
||||||
|
hasTexts,
|
||||||
|
hasImages,
|
||||||
|
hasSocials,
|
||||||
|
sectionHeight,
|
||||||
|
item: item,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
let result = `<td style="width: ${
|
let result = `<td style="width: ${
|
||||||
100 / section.columnsCount
|
100 / section.columnsCount
|
||||||
}%; height: ${sectionHeight}; background-color: ${
|
}%; height: ${sectionHeight}; background-color: ${
|
||||||
@@ -415,6 +453,11 @@ export const exportPersonalityToHTML = async (
|
|||||||
)}" style="padding: 8px;">
|
)}" style="padding: 8px;">
|
||||||
${renderImages(item?.images || [])}
|
${renderImages(item?.images || [])}
|
||||||
${renderSocials(item?.socials || [])}
|
${renderSocials(item?.socials || [])}
|
||||||
|
${
|
||||||
|
sectionHeight === "246px"
|
||||||
|
? '<div style="margin: 0 0 10px 0; text-align: right; color: #888; font-size: 14px;">{{content}}</div>'
|
||||||
|
: ""
|
||||||
|
}
|
||||||
${renderButtons(item.buttons)}
|
${renderButtons(item.buttons)}
|
||||||
</td>
|
</td>
|
||||||
</tr>`;
|
</tr>`;
|
||||||
@@ -438,8 +481,11 @@ export const exportPersonalityToHTML = async (
|
|||||||
${renderImages(item?.images || [])}
|
${renderImages(item?.images || [])}
|
||||||
${renderSocials(item?.socials || [])}
|
${renderSocials(item?.socials || [])}
|
||||||
${
|
${
|
||||||
isContentSection
|
sectionHeight === "246px" &&
|
||||||
? '<div style="margin: 0; text-align: right;">{{content}}</div>'
|
!hasTexts &&
|
||||||
|
!hasImages &&
|
||||||
|
!hasSocials
|
||||||
|
? '<div style="margin: 0; text-align: right; color: #888; font-size: 14px;">{{content}}</div>'
|
||||||
: ""
|
: ""
|
||||||
}
|
}
|
||||||
</td>
|
</td>
|
||||||
@@ -458,6 +504,18 @@ export const exportPersonalityToHTML = async (
|
|||||||
</tr>`;
|
</tr>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// اگر هیچ محتوایی نداریم و content section است
|
||||||
|
console.log(
|
||||||
|
"🔥 [ExportHTML] Empty content section detected, adding {{content}} placeholder"
|
||||||
|
);
|
||||||
|
if (sectionHeight === "246px") {
|
||||||
|
result += `<tr>
|
||||||
|
<td width="100%" height="230" style="padding: 20px; vertical-align: top; font-size: 15px; line-height: 1.8;">
|
||||||
|
<div style="margin: 0; text-align: right; color: #888; font-size: 14px;">{{content}}</div>
|
||||||
|
</td>
|
||||||
|
</tr>`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result += `</tbody>
|
result += `</tbody>
|
||||||
@@ -516,12 +574,13 @@ export const exportPersonalityToHTML = async (
|
|||||||
<table width="100%" cellpadding="0" cellspacing="0" border="0" style="border-collapse: collapse;">
|
<table width="100%" cellpadding="0" cellspacing="0" border="0" style="border-collapse: collapse;">
|
||||||
<tbody>
|
<tbody>
|
||||||
${renderSection(data.header, "123px")}
|
${renderSection(data.header, "123px")}
|
||||||
${renderSection(data.content, "246px", "", true)}
|
${renderSection(data.content, "246px", "")}
|
||||||
${renderSection(data.footer, "123px", "")}
|
${renderSection(data.footer, "123px", "")}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>`;
|
</div>`;
|
||||||
|
|
||||||
|
console.log("🔥 [ExportHTML] Final HTML generated:", html);
|
||||||
return html;
|
return html;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ const convertImagesToDataUrl = async (element: HTMLElement): Promise<void> => {
|
|||||||
const tempImg = new Image();
|
const tempImg = new Image();
|
||||||
tempImg.crossOrigin = "anonymous";
|
tempImg.crossOrigin = "anonymous";
|
||||||
|
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve) => {
|
||||||
tempImg.onload = () => {
|
tempImg.onload = () => {
|
||||||
canvas.width = tempImg.width;
|
canvas.width = tempImg.width;
|
||||||
canvas.height = tempImg.height;
|
canvas.height = tempImg.height;
|
||||||
|
|||||||
Reference in New Issue
Block a user