fix rtl and ltr text in new message
This commit is contained in:
@@ -7,7 +7,7 @@ VITE_SOCKET_URL = 'wss://dmail-api.danakcorp.com/email'
|
|||||||
# VITE_SOCKET_URL = 'ws://192.168.1.106:4000/email'
|
# VITE_SOCKET_URL = 'ws://192.168.1.106:4000/email'
|
||||||
|
|
||||||
VITE_BASE_URL = 'https://dmail-api.danakcorp.com'
|
VITE_BASE_URL = 'https://dmail-api.danakcorp.com'
|
||||||
# VITE_BASE_URL = 'http://192.168.1.106:4000'
|
# VITE_BASE_URL = 'http://192.168.1.117:4000'
|
||||||
|
|
||||||
|
|
||||||
VITE_SERVICE_ID = 'e51afdc3-ea0b-49cf-8f49-2a6f131b024e'
|
VITE_SERVICE_ID = 'e51afdc3-ea0b-49cf-8f49-2a6f131b024e'
|
||||||
|
|||||||
@@ -47,11 +47,15 @@ const EmailEditor: FC<EmailEditorProps> = ({
|
|||||||
line-height: 1.6;
|
line-height: 1.6;
|
||||||
min-height: 120px;
|
min-height: 120px;
|
||||||
}
|
}
|
||||||
.ql-editor p {
|
.ql-editor p, .ql-editor div, .ql-editor span {
|
||||||
unicode-bidi: plaintext;
|
unicode-bidi: plaintext;
|
||||||
text-align: start;
|
text-align: start;
|
||||||
direction: auto;
|
direction: auto;
|
||||||
}
|
}
|
||||||
|
.ql-editor br + * {
|
||||||
|
direction: auto;
|
||||||
|
unicode-bidi: plaintext;
|
||||||
|
}
|
||||||
.ql-editor.ql-blank::before {
|
.ql-editor.ql-blank::before {
|
||||||
direction: rtl;
|
direction: rtl;
|
||||||
text-align: right;
|
text-align: right;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { SendEmailDto, EmailAttachmentDto } from "@/pages/received/types/Types";
|
|||||||
import { useUpdateDraft, useSendDraft } from "@/pages/draft/hooks/useDraftData";
|
import { useUpdateDraft, useSendDraft } from "@/pages/draft/hooks/useDraftData";
|
||||||
import { toast } from "@/components/Toast";
|
import { toast } from "@/components/Toast";
|
||||||
import { useEmailSuggestions } from "./useEmailSuggestions";
|
import { useEmailSuggestions } from "./useEmailSuggestions";
|
||||||
|
import { detectTextDirection } from "@/helpers/utils";
|
||||||
|
|
||||||
export const useNewMessage = () => {
|
export const useNewMessage = () => {
|
||||||
const {
|
const {
|
||||||
@@ -143,13 +144,13 @@ export const useNewMessage = () => {
|
|||||||
try {
|
try {
|
||||||
let messageId = "";
|
let messageId = "";
|
||||||
if (isEditingDraft) {
|
if (isEditingDraft) {
|
||||||
|
const contentString = ensureString(content);
|
||||||
|
const textDirection = detectTextDirection(contentString);
|
||||||
const draftUpdateData = {
|
const draftUpdateData = {
|
||||||
to: parseEmailAddresses(toEmails),
|
to: parseEmailAddresses(toEmails),
|
||||||
subject,
|
subject,
|
||||||
html: `<div dir="auto" style="text-align: start; unicode-bidi: plaintext; font-family: 'Irancell', 'Vazirmatn', sans-serif;">${ensureString(
|
html: `<div dir="${textDirection}" style="text-align: start; unicode-bidi: plaintext; font-family: 'Irancell', 'Vazirmatn', sans-serif;">${contentString}</div>`,
|
||||||
content
|
text: contentString.replace(/<[^>]*>/g, ""),
|
||||||
)}</div>`,
|
|
||||||
text: ensureString(content).replace(/<[^>]*>/g, ""),
|
|
||||||
...(attachments.length > 0 && { attachments }),
|
...(attachments.length > 0 && { attachments }),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -172,9 +173,7 @@ export const useNewMessage = () => {
|
|||||||
messageId: editingDraftId.toString(),
|
messageId: editingDraftId.toString(),
|
||||||
draftData: {
|
draftData: {
|
||||||
...draftUpdateData,
|
...draftUpdateData,
|
||||||
html: `<div dir="auto" style="text-align: start; unicode-bidi: plaintext; font-family: 'Irancell', 'Vazirmatn', sans-serif;">${ensureString(
|
html: `<div dir="${textDirection}" style="text-align: start; unicode-bidi: plaintext; font-family: 'Irancell', 'Vazirmatn', sans-serif;">${contentString}</div>`,
|
||||||
content
|
|
||||||
)}</div>`,
|
|
||||||
isDraft: true,
|
isDraft: true,
|
||||||
uploadOnly: true,
|
uploadOnly: true,
|
||||||
},
|
},
|
||||||
@@ -196,14 +195,14 @@ export const useNewMessage = () => {
|
|||||||
setEditingDraftId(null);
|
setEditingDraftId(null);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
const contentString = ensureString(content);
|
||||||
|
const textDirection = detectTextDirection(contentString);
|
||||||
const emailData: SendEmailDto = {
|
const emailData: SendEmailDto = {
|
||||||
from: { address: userEmail || "sender@example.com" },
|
from: { address: userEmail || "sender@example.com" },
|
||||||
to: parseEmailAddresses(toEmails),
|
to: parseEmailAddresses(toEmails),
|
||||||
subject,
|
subject,
|
||||||
html: `<div dir="auto" style="text-align: start; unicode-bidi: plaintext; font-family: 'Irancell', 'Vazirmatn', sans-serif;">${ensureString(
|
html: `<div dir="${textDirection}" style="text-align: start; unicode-bidi: plaintext; font-family: 'Irancell', 'Vazirmatn', sans-serif;">${contentString}</div>`,
|
||||||
content
|
text: contentString.replace(/<[^>]*>/g, ""),
|
||||||
)}</div>`,
|
|
||||||
text: ensureString(content).replace(/<[^>]*>/g, ""),
|
|
||||||
...(attachments.length > 0 && { attachments }),
|
...(attachments.length > 0 && { attachments }),
|
||||||
...(isDraft && { isDraft: true, uploadOnly: true }),
|
...(isDraft && { isDraft: true, uploadOnly: true }),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -9,3 +9,32 @@ import { twMerge } from "tailwind-merge";
|
|||||||
export const clx = (...classes: (string | boolean | undefined)[]): string => {
|
export const clx = (...classes: (string | boolean | undefined)[]): string => {
|
||||||
return twMerge(classes.filter(Boolean).join(" "));
|
return twMerge(classes.filter(Boolean).join(" "));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detects the text direction based on the content
|
||||||
|
*
|
||||||
|
* @param text - The text to analyze
|
||||||
|
* @returns 'rtl' | 'ltr' | 'auto'
|
||||||
|
*/
|
||||||
|
export const detectTextDirection = (text: string): "rtl" | "ltr" | "auto" => {
|
||||||
|
// Remove HTML tags
|
||||||
|
const cleanText = text.replace(/<[^>]*>/g, "").trim();
|
||||||
|
if (!cleanText) return "auto";
|
||||||
|
|
||||||
|
// Count RTL and LTR characters
|
||||||
|
const rtlChars =
|
||||||
|
cleanText.match(
|
||||||
|
/[\u0590-\u083F\u08A0-\u08FF\uFB1D-\uFDFF\uFE70-\uFEFF]/g
|
||||||
|
) || [];
|
||||||
|
const ltrChars = cleanText.match(/[A-Za-z]/g) || [];
|
||||||
|
|
||||||
|
const rtlCount = rtlChars.length;
|
||||||
|
const ltrCount = ltrChars.length;
|
||||||
|
|
||||||
|
// If there's a significant difference, return that direction
|
||||||
|
if (rtlCount > ltrCount * 1.5) return "rtl";
|
||||||
|
if (ltrCount > rtlCount * 1.5) return "ltr";
|
||||||
|
|
||||||
|
// Otherwise, use auto
|
||||||
|
return "auto";
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user