소스 검색

Merge pull request #2318 from idomamia/feat/rtl-layout-chat-support

Add RTL layout chat support
Timothy Jaeryang Baek 11 달 전
부모
커밋
9e60d03911

+ 1 - 0
src/lib/components/chat/MessageInput.svelte

@@ -584,6 +584,7 @@
 						}}
 					/>
 					<form
+						dir={$settings?.chatDirection}
 						class=" flex flex-col relative w-full rounded-3xl px-1.5 bg-gray-50 dark:bg-gray-850 dark:text-gray-100"
 						on:submit|preventDefault={() => {
 							submitPrompt(prompt, user);

+ 1 - 1
src/lib/components/chat/Messages/CodeBlock.svelte

@@ -272,7 +272,7 @@ __builtins__.input = input`);
 </script>
 
 {#if code}
-	<div class="mb-4">
+	<div class="mb-4" dir="ltr">
 		<div
 			class="flex justify-between bg-[#202123] text-white text-xs px-4 pt-1 pb-0.5 rounded-t-lg overflow-x-auto"
 		>

+ 1 - 1
src/lib/components/chat/Messages/Name.svelte

@@ -1,3 +1,3 @@
-<div class=" self-center font-bold mb-0.5 line-clamp-1">
+<div class=" self-center font-bold mb-0.5 line-clamp-1 contents">
 	<slot />
 </div>

+ 3 - 1
src/lib/components/chat/Messages/ProfileImage.svelte

@@ -1,9 +1,11 @@
 <script lang="ts">
+	import { settings } from '$lib/stores';
 	import { WEBUI_BASE_URL } from '$lib/constants';
+  
 	export let src = '/user.png';
 </script>
 
-<div class=" mr-3">
+<div class={$settings?.chatDirection === 'LTR' ? "mr-3" : "ml-3"}>
 	<img
 		crossorigin="anonymous"
 		src={src.startsWith(WEBUI_BASE_URL) ||

+ 2 - 2
src/lib/components/chat/Messages/ResponseMessage.svelte

@@ -332,7 +332,7 @@
 <CitationsModal bind:show={showCitationModal} citation={selectedCitation} />
 
 {#key message.id}
-	<div class=" flex w-full message-{message.id}" id="message-{message.id}">
+	<div class=" flex w-full message-{message.id}" id="message-{message.id}" dir="{$settings.chatDirection}">
 		<ProfileImage
 			src={modelfiles[message.model]?.imageUrl ??
 				($i18n.language === 'dg-DG' ? `/doge.png` : `${WEBUI_BASE_URL}/static/favicon.png`)}
@@ -495,7 +495,7 @@
 									class=" flex justify-start overflow-x-auto buttons text-gray-600 dark:text-gray-500"
 								>
 									{#if siblings.length > 1}
-										<div class="flex self-center">
+										<div class="flex self-center" dir="ltr">
 											<button
 												class="self-center p-1 hover:bg-black/5 dark:hover:bg-white/5 dark:hover:text-white hover:text-black rounded-md transition"
 												on:click={() => {

+ 1 - 1
src/lib/components/chat/Messages/UserMessage.svelte

@@ -54,7 +54,7 @@
 	};
 </script>
 
-<div class=" flex w-full user-message">
+<div class=" flex w-full user-message" dir="{$settings.chatDirection}">
 	{#if !($settings?.chatBubble ?? true)}
 		<ProfileImage
 			src={message.user

+ 25 - 0
src/lib/components/chat/Settings/Interface.svelte

@@ -23,6 +23,7 @@
 	let promptSuggestions = [];
 	let showUsername = false;
 	let chatBubble = true;
+	let chatDirection: 'LTR' | 'RTL' = 'LTR';
 
 	const toggleSplitLargeChunks = async () => {
 		splitLargeChunks = !splitLargeChunks;
@@ -76,6 +77,11 @@
 		}
 	};
 
+	const toggleChangeChatDirection = async () => {
+		chatDirection = chatDirection === 'LTR' ? 'RTL' : 'LTR';
+		saveSettings({chatDirection});
+	};
+
 	const updateInterfaceHandler = async () => {
 		if ($user.role === 'admin') {
 			promptSuggestions = await setDefaultPromptSuggestions(localStorage.token, promptSuggestions);
@@ -114,6 +120,7 @@
 		chatBubble = settings.chatBubble ?? true;
 		fullScreenMode = settings.fullScreenMode ?? false;
 		splitLargeChunks = settings.splitLargeChunks ?? false;
+		chatDirection = settings.chatDirection ?? 'LTR';
 	});
 </script>
 
@@ -255,6 +262,24 @@
 			</div>
 		</div>
 
+		<div>
+			<div class=" py-0.5 flex w-full justify-between">
+				<div class=" self-center text-xs font-medium">{$i18n.t('Chat direction')}</div>
+
+				<button
+					class="p-1 px-3 text-xs flex rounded transition"
+					on:click={toggleChangeChatDirection}
+					type="button"
+				>
+					{#if chatDirection === 'LTR'} 
+						<span class="ml-2 self-center">{$i18n.t('LTR')}</span>
+					{:else}
+						<span class="ml-2 self-center">{$i18n.t('RTL')}</span>
+					{/if}
+				</button>
+			</div>
+		</div>
+
 		<hr class=" dark:border-gray-700" />
 
 		<div>

+ 3 - 0
src/lib/i18n/locales/en-US/translation.json

@@ -68,6 +68,7 @@
 	"Change Password": "",
 	"Chat": "",
 	"Chat Bubble UI": "",
+	"Chat direction": "",
 	"Chat History": "",
 	"Chat History is off for this browser.": "",
 	"Chats": "",
@@ -246,6 +247,7 @@
 	"Light": "",
 	"Listening...": "",
 	"LLMs can make mistakes. Verify important information.": "",
+	"LTR": "",
 	"Made by OpenWebUI Community": "",
 	"Make sure to enclose them with": "",
 	"Manage LiteLLM Models": "",
@@ -361,6 +363,7 @@
 	"Role": "",
 	"Rosé Pine": "",
 	"Rosé Pine Dawn": "",
+	"RTL": "",
 	"Save": "",
 	"Save & Create": "",
 	"Save & Update": "",

+ 1 - 0
src/lib/stores/index.ts

@@ -84,6 +84,7 @@ type Settings = {
 	notificationEnabled?: boolean;
 	title?: TitleSettings;
 	splitLargeDeltas?: boolean;
+	chatDirection: 'LTR' | 'RTL';
 
 	system?: string;
 	requestFormat?: string;